+ 1

Hello guys, I don't understand why the output is 106 can anyone help please?

public class Program { public static void main(String[] args) { char a='2',b='8'; System.out.println(a+b); } }

21st Aug 2019, 6:02 PM
Navneet
Navneet - avatar
2 Answers
+ 3
Because ascii value of '2' is 50 and '8' is 56 if you want the letter 'j' just cast it System.out.print((char)(a+b));
21st Aug 2019, 6:12 PM
D_Stark
D_Stark - avatar
+ 2
If you look at an ASCII table, '2' is not 2, but 32 (hex), or 50 (dec). Same for character '8': his value is 6 units more, 56. 50 + 56 = 106!
21st Aug 2019, 6:11 PM
Bilbo Baggins
Bilbo Baggins - avatar