Adding char and int

char, int, java

Solution

You're getting that because it's adding the ASCII value of the char. You must convert it to an int first.

Problem

To my understanding a char is a single character, that is a letter, a digit, a punctuation mark, a tab, a space or something similar. And therefore when I do: ``` char c = '1'; System.out.println(c); ``` The output 1 was exactly what I expected. So why is it that when I do this: ``` int a = 1; char c = '1'; int ans = a + c; System.out.println(ans); ``` I end up with the output 50?

Original source

Related problems