Let's look at it this way.
String code ="1123";
System.out.println( (code.charAt(0) - '1' + 'a' ));
In this case, the code.charAt(0)
call is essentially turning your code string into an array, and taking the 0-th element, which is 1.
So, the mathematics that are occurring are at the ASCII level, like you notated.
The ASCII value for 1 is 49, and the ASCII value for a is 97.
So the mathematics say: 49 - 49 + 97
Which, as we know, equals 97, which is what the output of this function is.
To recap:
- The String "code" is turned into an array of characters using the .charAt() function, and the 0th element of the array is referenced, which is 1
- The ASCII value of 1 is the subtracted from, 1
- The ASCII value of a is then printed, which is 97
Hopefully this helps!
EDIT: Here is a good reference for an ASCII lookup table: http://www.asciitable.com/