Java printing a String containing an integer

前端 未结 9 875
执笔经年
执笔经年 2021-01-02 02:54

I have a doubt which follows.

public static void main(String[] args) throws IOException{
  int number=1;
  System.out.println(\"M\"+number+1);
}
9条回答
  •  北海茫月
    2021-01-02 03:30

    If you perform + operation after a string, it takes it as concatenation:

    "d" + 1 + 1     // = d11 
    

    Whereas if you do the vice versa + is taken as addition:

    1 + 1 + "d"     // = 2d 
    

提交回复
热议问题