Why does concatenated characters print a number?

前端 未结 7 1730
离开以前
离开以前 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条回答
  •  猫巷女王i
    2020-12-16 05:28

    System.out.println("G" + "o");
      System.out.println('G' + 'o');
    

    First one + is acted as a concat operater and concat the two strings. But in 2nd case it acts as an addition operator and adds the ASCII (or you cane say UNICODE) values of those two characters.

提交回复
热议问题