Why does concatenated characters print a number?

前端 未结 7 1737
离开以前
离开以前 2020-12-16 04:44

I have the following class:

   public class Go {
     public static void main(String args[]) {
      System.out.println(\"G\" + \"o\");
      System.out.prin         


        
7条回答
  •  忘掉有多难
    2020-12-16 05:42

    In the second case it adds the unicode codes of the two characters (G - 71 and o - 111) and prints the sum. This is because char is considered as a numeric type, so the + operator is the usual summation in this case.

提交回复
热议问题