Why does concatenated characters print a number?

前端 未结 7 1720
离开以前
离开以前 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:29

    The plus in Java adds two numbers, unless one of the summands is a String, in which case it does string concatenation.

    In your second case, you don't have Strings (you have char, and their Unicode code points will be added).

提交回复
热议问题