I have noticed something strange when adding two chars in a string when casting them to an integer.
For the following code I have s1 = "+1" and s2 = "+2" as input:
String s1 = scanner.next();
String s2 = scanner.next();
System.out.println(s1.charAt(1));
System.out.println((int)s1.charAt(1));
The output is:
1
49
Then I tried also the following:
Input:
+1
+2
Code:
System.out.println(s1);
System.out.println(s2);
System.out.println((int)(s1.charAt(1)) + (int)(s2.charAt(1)));
Output:
+1
+2
99
Why is it like this? Why is the output not "3" and what can I do to get it to three?