JAVA程序中 + 号的使用

当左右两边都是数值型时,则做加法运算;

当左右两边有一边为字符串,则做拼接运算;

运算顺序,从左到右

1.System.out.println(100 + 3);  //输出为 103

2.System.out.println("100" + 98);  //输出为 10098

3.System.out.println(100 + 3 + "hello");  //输出为 103hello

System.out.println("hello" + 100 + 3);  // 输出为 hello1003

Guess you like

Origin blog.csdn.net/qq_43249582/article/details/121374962