why does a char + another char = a weird number

前端 未结 4 1720
猫巷女王i
猫巷女王i 2020-12-20 00:25

Here\'s the code snippet:

public static void main (String[]arg) 
{
    char ca = \'a\' ; 
    char cb = \'b\' ; 
    System.out.println (ca + cb) ; 
}
         


        
4条回答
  •  暖寄归人
    2020-12-20 00:57

    I don't speak Java, but 195 is 97 + 98 = the ASCII codes for a and b. So obviously, ca and cb are interpreted as their integer values, probably because of the + addition which does not seem to lead to a string concatenation automatically.

提交回复
热议问题