+ 2
System.out.println('h'+'i');
what is the output of this statement? Is the output a number? if so how?
3 Answers
+ 8
Since you used ' instead of ", it treats h and i as char. It takes their char values (ASCII values)and add them.
Remember a = 97. So:-
h = 104
i = 105
h + i = 209, thats your output.
+ 3
The + operator on characters add up their ascii values so it prints an integer. if you were using double quotes instead e.g.. "h"+"i", the + operator understands it is a concatenation of strings and the output would be "hi".
note also that :
system.out.printl('h') prints the character 'h', whereas
system.out.println('h'+0) prints the integer 104.
+ 2
Characters are represented as numbers in memory. You will probably get sum of ASCII values of 'h' and 'i'.