注意其中的微妙不同
- public class StringPlusInt {
- public static void main(String[] args) {
- int x=1,y=2,z=3;
- String s="str";
- System.out.println(x+y+z);
- System.out.println(s+x+y+z);
- System.out.println(x+y+z+s);
- System.out.println(s+(x+y+z));
- System.out.println("str2"+x+y+z);
- }
- }
结果:
6
str123
6str
str6
str2123
本文通过一个Java示例程序展示了字符串与整数相加的不同情况,解释了运算符在不同类型的数据间如何工作,特别是在混合类型操作中的行为差异。

被折叠的 条评论
为什么被折叠?



