+ 2

System.out.println('h'+'i');

what is the output of this statement? Is the output a number? if so how?

9th Dec 2017, 12:34 PM
Thriveni
Thriveni - avatar
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.
9th Dec 2017, 12:42 PM
Meharban Singh
Meharban Singh - avatar
+ 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.
9th Dec 2017, 1:01 PM
ifl
ifl - avatar
+ 2
Characters are represented as numbers in memory. You will probably get sum of ASCII values of 'h' and 'i'.
9th Dec 2017, 12:41 PM
Daniel Oravec
Daniel Oravec - avatar