Beginning Java - Off-topic

Hi!
If you're beginning Java like me, then share your code here!
Simply use the code tags.
Here's my latest application:
Code:
package name;
import java.util.Scanner;
public class Name {
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
String first_name;
System.out.print("Enter your first name: ");
first_name = user_input.next();
String surname;
System.out.print("Enter your surname: ");
surname = user_input.next();
String age;
System.out.print("How old are you: ");
age = user_input.next();
String full_name;
full_name = first_name + " " + surname;
System.out.println("You are " + full_name + "." + "You are also " + age + " " + "years old.");
System.out.println("Note that some of this information may not be true, since it it the information you or someone/something else provided.");
System.out.println("You got a problem with that?!?!");
System.out.println("Thank you for using my awesome Java application!");
}
}
So, post yours!!

Right. I see there aren't many people Beginning Java round here.

Bad-Wolf said:
Right. I see there aren't many people Beginning Java round here.
Click to expand...
Click to collapse
Nope. I had 1 semester of Java well over a year ago. I forgot most of it since I started c++, which I forgot also the day after the semester ended.

I was learning c#, but then i realized that it's a crap language and im not going to get anywhere using it, so i started learning Java, which i'm trying hard to remember, and as you have seen, i have.

Yea Java is the **** right now. C++ is good for windows only. I have to see if I can continue taking Java in college instead of C++. And it is so much easier than C++ or any C language for that matter.

I used to study Java but my college wants C++. I think Java is easier when it comes to GUI.
Sent from my SGH-T959 using XDA App

Agreed.
10chars

Well, isn't anyone going to post anything? Even a hello world is good enough here!
Sent from a Time Lord, using his TARDIS.

Get your grey matter round this one!
Code:
public class test
{
static String startstring;
static int startlen;
public static void main(String[] args)
{
startstring = args[0];
startlen=startstring.length();
genanag(args[0].substring(0,1),args[0].substring(1,2));
}
public static void genanag(String oldstring, String insert)
{
String newstring;
int i;
int oldlen=oldstring.length();;
for(i=0;i<=oldlen;i++)
{
newstring=oldstring.substring(0,i)+insert+oldstring.substring(i);
if(newstring.length()==startlen)
System.out.print(newstring+"\n");
else
genanag(newstring,startstring.substring(oldlen+1,oldlen+2));
}
}
}
When you run it you get this :
Code:
C:\PROGRA~1\Java\JDK16~1.0_2\bin>java test ABCD
DCBA
CDBA
CBDA
CBAD
DBCA
BDCA
BCDA
BCAD
DBAC
BDAC
BADC
BACD
DCAB
CDAB
CADB
CABD
DACB
ADCB
ACDB
ACBD
DABC
ADBC
ABDC
ABCD
C:\PROGRA~1\Java\JDK16~1.0_2\bin>

stephj said:
Get your grey matter round this one!
Code:
public class test
{
static String startstring;
static int startlen;
public static void main(String[] args)
{
startstring = args[0];
startlen=startstring.length();
genanag(args[0].substring(0,1),args[0].substring(1,2));
}
public static void genanag(String oldstring, String insert)
{
String newstring;
int i;
int oldlen=oldstring.length();;
for(i=0;i<=oldlen;i++)
{
newstring=oldstring.substring(0,i)+insert+oldstring.substring(i);
if(newstring.length()==startlen)
System.out.print(newstring+"\n");
else
genanag(newstring,startstring.substring(oldlen+1,oldlen+2));
}
}
}
When you run it you get this :
Code:
C:\PROGRA~1\Java\JDK16~1.0_2\bin>java test ABCD
DCBA
CDBA
CBDA
CBAD
DBCA
BDCA
BCDA
BCAD
DBAC
BDAC
BADC
BACD
DCAB
CDAB
CADB
CABD
DACB
ADCB
ACDB
ACBD
DABC
ADBC
ABDC
ABCD
C:\PROGRA~1\Java\JDK16~1.0_2\bin>
Click to expand...
Click to collapse
THAT!
IS!
COOL!
Unfortunately I'm not uo to that stage yet. Moving onto Joptionpane next, whatever that is.LOl. Where'dya learn Java.

Allow me to do some experimental BB Code programming!
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}

Bad-Wolf said:
Where'dya learn Java.
Click to expand...
Click to collapse
I have been programming for years, originally in COBOL.
The ability to code in Java came from learning C#, from previously learning C++, itself from C. (Other languages include Fortran, 370 Assember, PC Assembler and RPG III/IV, but none of these have much in common with object orientated programming.)
While the C# and Java communities seem to take great delight in throwing brickbats at each other from their respective trenches, there is not really a great deal of difference between the two languages, not any that are worth getting upset about!
Right let's make it do something vaguely useful.......... This was originally coded in C# as a solution to the following post.
http://forum.xda-developers.com/showthread.php?t=1435629
ISO6346 defines the layout of serial numbers and the checksum digit for intermodal containers. (The 20 and 40 ft metal containers used to ship almost everything these days.) :- http://en.wikipedia.org/wiki/ISO_6346
This code takes the first ten characters of the serial number and calculates the checksum digit. The argument must be of the form ABCD123456 or there is no response:
Code:
public class ISO6346
{
public static void main(String[] args)
{
String Input = args[0].toUpperCase();
int i,j,k;
if(Input.matches("[A-Z]{4}[0-9]{6}"))
{
k=0;
for (i=0; i<10; i++)
{
j = Input.charAt(i);
if (j > 64 && j < 91)
k += ((j - 55) + (j - 56) / 10) << i;
else
k += (j - 48) << i;
}
k = ((k % 11) % 10);
System.out.print(Input.substring(0,4)+" "+Input.substring(4)+" "+k);
}
}
}
Results in:
Code:
C:\Program Files\Java\jdk1.6.0_23\bin>JAVA ISO6346 TOLU473478
TOLU 473478 7
C:\Program Files\Java\jdk1.6.0_23\bin>
Compare the result with the image in the top right of the Wikipedia page.......... and that concludes the case for the defense, Your Honour!

As my current Project is based on JSP, I'll share the crap I'm doing now :
Function for Inserting datas into database (Anyways the database should be connected before doing this [includes code] + --> Connection con = null; PreparedStatement ps = null
Code:
public boolean FunctionName(String name, String address, String phoneno)
{
boolean flag = false;
try {
ps = con.prepareStatement("insert into TABLE_NAME(FIELD_1,FIELD2,FIELD_3) values(?,?,?)");
ps.setString(1,name);
ps.setString(2,address);
ps.setString(3,phoneno);
ps.executeUpdate();
flag = true;
}
catch(Exception e) {
System.out.println("Error in Insertion"+e);
}
return flag;
}
+
HTML / JSP Design Page should be there to get values from user (Textbox)
+
JSP action page should be there to trigger action when user clicks the button on the design page.

Where would anyone here recommend starting to learn Java from? Online, books, classes? Just starting out and not sure which is the best place to go first? I have dl Java sdk and eclipse but that's about as far as I'm at.
Sent from my GT-P7300 using Tapatalk

Database Connection code (Mysql is discussed) :
Code:
package com.db; //Package name optional
import java.sql.*;
public class DbConnection()
{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null; //ResultSet is useful for Select queries
public DbConnection() //Create a constructor
{
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/DATABASE_NAME","root",""); //I guess root is default in Mysql
}
catch(Exception e) {
System.out.println("Error in Connection"+e);
}
}
}
---------- Post added at 08:09 PM ---------- Previous post was at 08:04 PM ----------
Aust S5 said:
Where would anyone here recommend starting to learn Java from? Online, books, classes? Just starting out and not sure which is the best place to go first? I have dl Java sdk and eclipse but that's about as far as I'm at.
Sent from my GT-P7300 using Tapatalk
Click to expand...
Click to collapse
The best reference for Core Java (ie, Java SE) I'd recommend "The Complete Reference Java Seventh Edition (Or Fifth Edition) by Herbert Schildt"
And don't start studying Java using IDE (like Eclipse or Netbeans)
Start writing code using simple Notepad or Notepad++ and compile it in Command Prompt. This is the best way for freshers.

Aust S5 said:
Where would anyone here recommend starting to learn Java from? Online, books, classes? Just starting out and not sure which is the best place to go first? I have dl Java sdk and eclipse but that's about as far as I'm at.
Sent from my GT-P7300 using Tapatalk
Click to expand...
Click to collapse
I love this book.
http://www.amazon.com/Head-First-Ja...9208/ref=sr_1_1?ie=UTF8&qid=1331745451&sr=8-1

Thanks guys I'll look into both of these. I'm looking forwards to learning all i can. Fingers crossed
sent from Grey Skull

As Java used to be owned by Sun, before they themselves were bought by Oracle, there is a whole load of documentation beginning here:
http://docs.oracle.com/javase/
As well as here:
http://www.oracle.com/technetwork/java/javase/overview/index.html
The API documentation is useful when you need to find which method of which object you need to do the job.

Simple java code
one of first for math (ax^2+bx+c)
Code:
int a=2; //example
int b=3;
int c=4;
for (int i = 0; i<=100;i++){
if((a*(i*i)+b*i+c)==4)
system.out.println(i);
}

That is beyond me! If I had more time, I would be learning Java quicker.
Sent from a Time Lord, using his TARDIS.

Related

Want a job with GCHQ?

Crack the code found here:
http://www.canyoucrackit.co.uk/
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
It's Hexadecimal isn't it? Wheres stephj when you need him?
Yeah, it's hex, but to convert it to any other format would still just be numbers. We need to figure out what the numbers mean. I did have a look at it earlier and fancy giving it a go. Not sure where to start so I'll just jump in and see what happens. (Later, after work)
Meh..... numbers.....
I'll pass.
If it were masonic/occult symbols I may be interested.
Sent From My Fingers To Your Face......
conantroutman said:
Meh..... numbers.....
I'll pass.
If it were masonic/occult symbols I may be interested.
Sent From My Fingers To Your Face......
Click to expand...
Click to collapse
Maybe when converted to decimal the number refer to chapters from the book of revelations
A bit more juicy for you?
The answer is 42.
-We do what we must because we can; for the good of all of us, except the ones who are dead-
I_am_Error said:
The answer is 42.
-We do what we must because we can; for the good of all of us, except the ones who are dead-
Click to expand...
Click to collapse
Always! In a delicious twist of fate that Douglas Adams would have appreciated, my vending machine coffee number at work is... 42.
Archer said:
Maybe when converted to decimal the number refer to chapters from the book of revelations
A bit more juicy for you?
Click to expand...
Click to collapse
Ooh me likey....
You crunch the numbers, I'll start running Da Vincis through the IR scanner......
Sent From My Fingers To Your Face......
DirkGently said:
It's Hexadecimal isn't it? Wheres stephj when you need him?
Click to expand...
Click to collapse
I must admit to having had a bit of a dabble at this, as it was plastered all over the daily papers today. Tried a bit of classic cypher stuff, but to no avail, yet.
If I find the location of the Holy Grail, I'll get back to you.
As I have already got the hex values from the screen shot above, typed into a text file, and if anyone else fancies a crack at it, it's attached here in order to save you having to punch the data in yourself.
Good Luck!
PS. 'Punch' is a reference to a mainframe machine's 80 column punched cards. Very old hat now, but old terms die hard!
PPS. Ever wondered why console screens, (Window's CMD.EXE)/(Linux Konsole shell), are always 80 columns across? Might the two be related?
The truth is out there. Literally. There's a pastebin of some computer code that resolves the puzzle.
The hex has to be turned into an .exe or some such sorcery. I'll track down a link...
Edit: http://pastebin.com/cqzbkw4H
Somebody posted the website you reach if you crack the code:
http://www.canyoucrackit.co.uk/soyoudidit.asp
(So tempted to Rickroll everone there but i would never be so passe)!
When this ends up to be some gibberish about the widows son and you guys are all found hanging under a bridge with a square and compass carved into your chests.....
Don't say I didn't warn ya..........
conantroutman said:
When this ends up to be some gibberish about the widows son and you guys are all found hanging under a bridge with a square and compass carved into your chests.....
Don't say I didn't warn ya..........
Click to expand...
Click to collapse
^^ He's probably in on it too....
Anyway, can't stop... g
Gonna rip open as many doors on my Scottish advent calendar as I can before the missus gets home....
Conan is into the occult and the supernatural?! Or mystic or...whatever?! No wonder why he has super powers...
-We do what we must because we can; for the good of all of us, except the ones who are dead-
I_am_Error said:
Conan is into the occult and the supernatural?! Or mystic or...whatever?! No wonder why he has super powers...
-We do what we must because we can; for the good of all of us, except the ones who are dead-
Click to expand...
Click to collapse
Nah.... I just like a nice juicy conspiracy... and have a phobia of freemasons
conantroutman said:
Nah.... I just like a nice juicy conspiracy... and have a phobia of freemasons
Click to expand...
Click to collapse
It is a reasonable phobia. We got tons of them secretly in our government
-We do what we must because we can; for the good of all of us, except the ones who are dead-
I'm deleting my posts and getting the hell out of here before Elgoog caches this....
"You aint seen me. Right?"
conantroutman said:
...and have a phobia of freemasons
Click to expand...
Click to collapse
I bet you do. Nudge, nudge... wink, wink!
*funny handshake
Do you need a new advent calender yet or still working on that one?
DirkGently said:
I bet you do. Nudge, nudge... wink, wink!
*funny handshake
Do you need a new advent calender yet or still working on that one?
Click to expand...
Click to collapse
Creepy old men in intricately decorated aprons riding goats.....
What's not to be afraid of...........
Still have about 8 cans left so I'm good for another 5/10 minutes... thanks..
Some of the UK daily press have let some of the cats out of the bag.
http://www.telegraph.co.uk/news/ukn...-GCHQ-code-directed-to-25000-job-vacancy.html
It would also appear that the hex digits are 32 bit 80386 or later machine code, so lets do this step at least.
The following 'C' code takes the file HEXCODE.TXT and converts it to the binary file HEXCODE.BIN
HEXCODE.ZIP contains HEXCODE.BIN
Code:
#include <stdio.h>
main()
{
char hex[16];
char buffer[100];
int i;
FILE *in,*out;
if((in=fopen("hexcode.txt","r"))==NULL)
{
printf("Can't open input HEXCODE.TXT\n");
return(1);
}
if((out=fopen("hexcode.bin","wb"))==NULL)
{
printf("Can't open output HEXCODE.BIN\n");
return(1);
}
while(fgets(buffer,100,in))
{
sscanf(buffer,"%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X
%02X %02X",
&hex[0],&hex[1],&hex[2],&hex[3],&hex[4],&hex[5],&hex[6],&hex[7],
&hex[8],&hex[9],&hex[10],&hex[11],&hex[12],&hex[13],&hex[14],&hex[15]);
fwrite(hex,1,16,out);
}
fclose(in);
fclose(out);
return(0);
}
This file can then be loaded into a dissassembler. The command line version of DEBUG.EXE has an inbuilt disassembler, but it can't cut it as it is only 16 bit. The freeware version of IDA being an excellent tool for the job. Once you have told it that the code is 32 bit and the code starts at offset 0, it reveals the following code. Time to brush up your 32 bit x86 assembler.
Code:
seg000:00000000 seg000 segment byte public 'CODE' use32
seg000:00000000 assume cs:seg000
seg000:00000000 assume es:nothing, ss:nothing, ds:nothing, fs:nothing, gs:nothing
seg000:00000000 jmp short loc_6
seg000:00000000 ; ---------------------------------------------------------------------------
seg000:00000002 db 0AFh ; »
seg000:00000003 db 0C2h ; -
seg000:00000004 db 0BFh ; +
seg000:00000005 db 0A3h ; ú
seg000:00000006 ; ---------------------------------------------------------------------------
seg000:00000006
seg000:00000006 loc_6: ; CODE XREF: seg000:00000000j
seg000:00000006 sub esp, 100h
seg000:0000000C xor ecx, ecx
seg000:0000000E
seg000:0000000E loc_E: ; CODE XREF: seg000:00000013j
seg000:0000000E mov [esp+ecx], cl
seg000:00000011 inc cl
seg000:00000013 jnz short loc_E
seg000:00000015 xor eax, eax
seg000:00000017 mov edx, 0DEADBEEFh
seg000:0000001C
seg000:0000001C loc_1C: ; CODE XREF: seg000:00000032j
seg000:0000001C add al, [esp+ecx]
seg000:0000001F add al, dl
seg000:00000021 ror edx, 8
seg000:00000024 mov bl, [esp+ecx]
seg000:00000027 mov bh, [esp+eax]
seg000:0000002A mov [esp+eax], bl
seg000:0000002D mov [esp+ecx], bh
seg000:00000030 inc cl
seg000:00000032 jnz short loc_1C
seg000:00000034 jmp loc_95
seg000:00000039
seg000:00000039 ; ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ S U B R O U T I N E ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦
seg000:00000039
seg000:00000039
seg000:00000039 sub_39 proc near ; CODE XREF: sub_39+5Ep
seg000:00000039 mov ebx, esp
seg000:0000003B add ebx, 4
seg000:00000041 pop esp
seg000:00000042 pop eax
seg000:00000043 cmp eax, 41414141h
seg000:00000048 jnz short loc_8D
seg000:0000004A pop eax
seg000:0000004B cmp eax, 42424242h
seg000:00000050 jnz short loc_8D
seg000:00000052 pop edx
seg000:00000053 mov ecx, edx
seg000:00000055 mov esi, esp
seg000:00000057 mov edi, ebx
seg000:00000059 sub edi, ecx
seg000:0000005B rep movsb
seg000:0000005D mov esi, ebx
seg000:0000005F mov ecx, edx
seg000:00000061 mov edi, ebx
seg000:00000063 sub edi, ecx
seg000:00000065 xor eax, eax
seg000:00000067 xor ebx, ebx
seg000:00000069 xor edx, edx
seg000:0000006B
seg000:0000006B loc_6B: ; CODE XREF: sub_39+52j
seg000:0000006B inc al
seg000:0000006D add bl, [esi+eax]
seg000:00000070 mov dl, [esi+eax]
seg000:00000073 mov dh, [esi+ebx]
seg000:00000076 mov [esi+eax], dh
seg000:00000079 mov [esi+ebx], dl
seg000:0000007C add dl, dh
seg000:0000007E xor dh, dh
seg000:00000080 mov bl, [esi+edx]
seg000:00000083 mov dl, [edi]
seg000:00000085 xor dl, bl
seg000:00000087 mov [edi], dl
seg000:00000089 inc edi
seg000:0000008A dec ecx
seg000:0000008B jnz short loc_6B
seg000:0000008D
seg000:0000008D loc_8D: ; CODE XREF: sub_39+Fj
seg000:0000008D ; sub_39+17j
seg000:0000008D xor ebx, ebx ; status
seg000:0000008F mov eax, ebx
seg000:00000091 inc al
seg000:00000093 int 80h ; LINUX - sys_exit
seg000:00000095
seg000:00000095 loc_95: ; CODE XREF: seg000:00000034j
seg000:00000095 nop
seg000:00000096 nop
seg000:00000097 call sub_39
seg000:0000009C inc ecx
seg000:0000009D inc ecx
seg000:0000009E inc ecx
seg000:0000009F inc ecx
seg000:0000009F sub_39 endp
seg000:0000009F
seg000:0000009F seg000 ends
seg000:0000009F
seg000:0000009F
seg000:0000009F end
There are one or two things to note about this code. It appears to have been hand written, as it is does not carry the signature of a compiler. It has probably designed to run on a Linux OS distro, as there is no usual 'Windows' end/exit/return to the procedure, namely a RET instruction. Instead it uses an INT 80h interrupt. also note the DEADBEEF reference at 0x17
This code is used to decrypt a message hidden in the CYBER.PNG file itself, which is the image in the first post.
I'm off to hide under the bed now, there are two Men in Black peering through the window!

Another Math Problem

6 ÷ 2 (2 + 1) =x
1
2chars
Edit after so many days:
The answer doesn't matter. No matter what happens, I'll be proved right AND wrong, having been the point of countless arguments forthcoming in the thread you're about to read.
Its so pointless/repetative/annoying, I don't even wanna argue.
If you use order of operation the answer is 9.
Multiplication and*Division (left-to-right)
Sent from the Galaxy beast note ll
85gallon said:
6 ÷ 2 (2 + 1) =x
Click to expand...
Click to collapse
My answer is with respect to BODMAS, just to clear things up
Lol I know BIDMAS but whats BODMAS(Is it Brackets of divison Multipication Addition and Subtraction
Sent from my GT-S5660 using xda app-developers app
batman38102 said:
Lol I know BIDMAS but whats BODMAS(Is it Brackets of divison Multipication Addition and Subtraction
Sent from my GT-S5660 using xda app-developers app
Click to expand...
Click to collapse
Lol its the other way round for me
Its that only...
Will have to google bidmas in the morning
a.cid said:
Lol its the other way round for me
Its that only...
Will have to google bidmas in the morning
Click to expand...
Click to collapse
There's only bodmas!
Sent from my HTC Explorer A310e using xda app-developers app
In the USofA they use PEMDAS.
Parenthases, exponent, multiplication, division, addition and subtraction.
Annd the result is
x = 9;
I'm curious, why is there a thread dedicated to such a basic math formulae
Smoking is one of the leading causes of statistics.
- Fletcher Knebel
jugg1es said:
I'm curious, why is there a thread dedicated to such a basic math formulae
Smoking is one of the leading causes of statistics.
- Fletcher Knebel
Click to expand...
Click to collapse
It was started by a noob, not like he knows better
Since pemdas and bodmas as are used in various areas left to right for multiplication and division is used by default for mathematicians yielding 9 as the answer
Sent from my Galaxy Nexus using xda app-developers app
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Problem solved. Spiderman time?
LoopDoGG79 said:
Problem solved. Spiderman time?
Click to expand...
Click to collapse
Sounds good to me
Smoking is one of the leading causes of statistics.
- Fletcher Knebel
PEMDAS, BIMDAS, whatever you want to use, the way it's written the answer is 1. You only get nine if you divide first, which is not how it works. Order of operations states that you take care of the parenthetical operators first, then multiplication, then division.
Honestly, the problem is poorly written and would never appear in a text or problem set that way.
MissionImprobable said:
PEMDAS, BIMDAS, whatever you want to use, the way it's written the answer is 1. You only get nine if you divide first, which is not how it works. Order of operations states that you take care of the parenthetical operators first, then multiplication, then division.
Honestly, the problem is poorly written and would never appear in a text or problem set that way.
Click to expand...
Click to collapse
Multiplication and division are on the same level and go from left to right.
MissionImprobable said:
PEMDAS, BIMDAS, whatever you want to use, the way it's written the answer is 1. You only get nine if you divide first, which is not how it works. Order of operations states that you take care of the parenthetical operators first, then multiplication, then division.
Honestly, the problem is poorly written and would never appear in a text or problem set that way.
Click to expand...
Click to collapse
You dare question Google!?!?
85gallon said:
6 ÷ 2 (2 + 1) =x
Click to expand...
Click to collapse
so...im ten yrs old...i moved from romania to uk...go to school and then i give that to the class...nobody did that! The teacher didnt know to do this xD funny...really...uk schools-low...can u do it?:
a+b=522
a+c=303
c+b=425
Find a, b and c...
Obviously none of you people know the maths.
Everyone who knows maths knows that: X = Purple.
raducu7890 said:
so...im ten yrs old...i moved from romania to uk...go to school and then i give that to the class...nobody did that! The teacher didnt know to do this xD funny...really...uk schools-low...can u do it?:
a+b=522
a+c=303
c+b=425
Find a, b and c...
Click to expand...
Click to collapse
a + b = 522
a + c = 303
c + b = 425
a + b + a + c = 522 + 303
2a + b + c = 825
2a + b + c - (b + c) = 825 - 425
2a = 400
a = 200
200 + b = 522
b = 522 - 200
b = 322
200 + c = 303
c = 303 - 200
c = 103
I'm 40 - and I haven't forgotten my basic maths
Schooling in Romania is actually better than in the UK, mainly because most of the kids actually WANT to learn there.
SimonTS said:
a + b = 522
a + c = 303
c + b = 425
a + b + a + c = 522 + 303
2a + b + c = 825
2a + b + c - (b + c) = 825 - 425
2a = 400
a = 200
200 + b = 522
b = 522 - 200
b = 322
200 + c = 303
c = 303 - 200
c = 103
I'm 40 - and I haven't forgotten my basic maths
Schooling in Romania is actually better than in the UK, mainly because most of the kids actually WANT to learn there.
Click to expand...
Click to collapse
The things is, the teachers are putting maths in them...hard work...here(in UK, Year 6) nobody knows algebra...they know just :
% / - + °

JAVA code undesired output!! help!! NOT related to Android!

Hi devs! I'm pretty noob in programming. While working on a simple Java program in Eclipse, related to formatting strings, I came around a problem where I'm not getting an output which is expected from the lines of code.
Here's the code:
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
But I got this as output:
But from the code, the expected output is this, right??
Where did I go wrong??
Hi, you could try using the following. I think it should work but I also have limited knowledge of Java.
Set these variables inside for loop
int square = i*i
int cube = i*i*i
Replace the f.format line and the print output with the following.
System.out.format("%10d%10d%10d", i, square, cube)
Sent from my Nexus 7 using Tapatalk HD
veeman said:
Hi, you could try using the following. I think it should work but I also have limited knowledge of Java.
Set these variables inside for loop
int square = i*i
int cube = i*i*i
Replace the f.format line and the print output with the following.
System.out.format("%10d%10d%10d", i, square, cube)
Sent from my Nexus 7 using Tapatalk HD
Click to expand...
Click to collapse
That worked Veeman! :good: :victory: But I had to add a \n to get a new line. Thanks a ton! cheers!
Btw, can you give a detail about that?? about, why it happened?? Thanks again..
chandujram said:
That worked Veeman! :good: :victory: But I had to add a \n to get a new line. Thanks a ton! cheers!
Btw, can you give a detail about that?? about, why it happened?? Thanks again..
Click to expand...
Click to collapse
I think your problem was just using the format wrong.
Sent from my Nexus 7 using Tapatalk HD
Here's why your original code produces the results it does. 'veeman' is correct in that is not the way you would normally use a formatter. Instead you would use the format() method of System.out to present the output how you want it, as shown in post #2 above.
Your original code has created a Formatter with the default constructor. i.e. nothing passed as parameters in the call to create the 'new' object.
From the documentation in: -
http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html
we have: -
public Formatter()
Constructs a new formatter.
The destination of the formatted output is a StringBuilder which may be retrieved by invoking out() and whose current content may be converted into a string by invoking toString(). The locale used is the default locale for this instance of the Java virtual machine.
Click to expand...
Click to collapse
Therefore, the destination of this object, (i.e. where its output is going to), is the Formatter's own internal appendable Stringbuilder object.
By using f.format(....) you are writing to the end of this stringbuilder object.
This explains why you are printing out a string that increases by the next term each time.
To make your code use the formatter correctly, you need to do something like this:
Code:
import java.util.*;
public class FormatDemo {
public static void main(String[] args) {
Formatter f=new Formatter();
for (int i=0;i<10;i++) {
f.format("%d\n",i*i*i);
}
f.out();
}
}
Code:
C:\PROGRA~1\Java\JDK17~1.0_0\bin>javac FormatDemo.java
C:\PROGRA~1\Java\JDK17~1.0_0\bin>java FormatDemo
0
1
8
27
64
125
216
343
512
729
C:\PROGRA~1\Java\JDK17~1.0_0\bin>
P.S. This isn't really OT, if a mod wants to shift it over to Q&A.
stephj said:
P.S. This isn't really OT, if a mod wants to shift it over to Q&A.
Click to expand...
Click to collapse
It's fine here - it's not related to phones so doesn't belong in any of the other Q&A or app development forums.
I'm a little surprised by this though. I can see what it's doing, but have no idea why it would. Admittedly I'm not au-fait with Java yet, but I know enough about C based languages to say, "eh?"
Edit: I take that back - just read your post properly
Yeah okey. I got it.. Thanx everyone for the reply. Actually there is another careless mistake in the program I pasted above. But anyway good for me that you guys knew what I was trying to ask. Thanx again! :highfive:

[Q] hookSystemWideLayout in layout-sw360dp-xhdpi

Hello,
my code dont give me something back, no error, nothing.
the "global_actions_view_cover.xml" is in "layout-sw360dp-xhdpi".
whats wrong with my code?
Code:
@Override
public void initZygote(StartupParam startupParam) throws Throwable {
XResources.hookSystemWideLayout("android", "layout", "global_actions_view_cover", new XC_LayoutInflated() {
@Override
public void handleLayoutInflated(LayoutInflatedParam liparam) throws Throwable {
XposedBridge.log(LOG_TAG + "global_actions_view_cover");
}
});
}
thanks for helping
That'll only be inflated if your device's width is higher than 360dp and it's an XHDPI device. Not sure what will happen if there are multiple matches.
See this for more info.

Do I need to try/catch findAndHookMethod()'s?

As the title implies, if I do
Code:
findAndHookMethod() { //method 1
}
findAndHookMethod() { //method 2
}
do I have to try/catch each call in order for it to reach //method 2 in case //method 1 isn't found?
Also what happens if I get an Exception inside:
Code:
afterHookedMethod(MethodHookParam param) throws Throwable
?
Do I have to make sure no Exception escapes from that hook?
Where is such an Exception caught? Will it break the program being manipulated, or will it just be disregarded?

Categories

Resources