Java String Concatenation with + operator

后端 未结 5 1182
深忆病人
深忆病人 2020-11-28 15:57

I got confused with the String concatenation.

String s1 = 20 + 30 + \"abc\" + (10 + 10);
String s2 = 20 + 30 + \"abc\" + 10 + 10;
System.out.println(s1);
Sys         


        
5条回答
  •  鱼传尺愫
    2020-11-28 16:34

    You will need to start with an empty string.

    So, this might work:

    String s2 = ""+20+30+"abc"+10+10; 
    

    Or this:

    String s2 ="";
    s2 = 20+30+"abc"+10+10;
    System.out.println(s2);
    

提交回复
热议问题