-2

I tried running this program but I never understood how this result turned up...I tried to add the ASCII value of B to 2 and that would have made the output 68 but the actual answer is completely different....

char a = 'B',b='2'; into c= a+b; System.out.println(c);. 

Output:116

I don't understand how is this even coming??

mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • 3
    https://stackoverflow.com/questions/245062/whats-the-difference-between-javascript-and-java – mplungjan Mar 21 '18 at 10:53
  • Welcome to Stack Overflow! Please visit the [help], take the [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output. – mplungjan Mar 21 '18 at 10:54
  • 3
    `'B'` is ascii 66, `'2'` is ascii 50 => 66 + 50 + 116 . `char`s are not strings. – Federico klez Culloca Mar 21 '18 at 10:54
  • To know what's the value of `'2'`, just do `System.out.println((int)'2')`. Easy as that. – user202729 Mar 21 '18 at 10:54

1 Answers1

3

here b is character '2'. So the ASCII value used for that is 50. and ASCII value of 'B' is 66. So the total is 116.

Rahul Patel
  • 639
  • 6
  • 12