English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

System.out.println('a' + 3 + "Bye");

is displayed as

100Bye

What rule(s) is Java using in deciding what to print?

2006-10-26 17:07:55 · 2 answers · asked by javaHungerForce 3 in Computers & Internet Programming & Design

2 answers

here you put [a] in single quotes which means it is a char
java adds it ascii equivalent to 3, since ascii equivalent of [a] is 97
java resolves 97+3=100 then it concatenates with the string Bye.
hence the output
100Bye

good Luck.

2006-10-26 18:36:04 · answer #1 · answered by Anand 3 · 3 0

When you add a char ('a') to an int, the char is converted to its numeric representation 97 is the numeric value of 'a' and added to the int.

Finally the integer (100) is converted to a string when it's added to "Bye".

2006-10-26 17:12:35 · answer #2 · answered by M. Dizzy 2 · 1 0

fedest.com, questions and answers