、、、、
、、、、、 byte by=5;
short sh=6;
int num=7;
char ch='a';
float fl=8.0f;
double dou=9.0;
String str="abcdef";
System.out.println(by+sh+num+ch+fl+dou+str);
System.out.println(by+sh+num+ch+str+fl+dou);
System.out.println(str+by+sh+num+ch+fl+dou);
、、、、、、、、 得到的三个结果如下:
132.0abcdef
115abcdef8.09.0
abcdef567a8.09.0
、、、、、 byte by=5;
short sh=6;
int num=7;
char ch='a';
float fl=8.0f;
double dou=9.0;
String str="abcdef";
System.out.println(by+sh+num+ch+fl+dou+str);
System.out.println(by+sh+num+ch+str+fl+dou);
System.out.println(str+by+sh+num+ch+fl+dou);
、、、、、、、、 得到的三个结果如下:
132.0abcdef
115abcdef8.09.0
abcdef567a8.09.0
1 by+sh=11+num=18+ch=18+ASCII('a')=18+97=115+8.0f+9.0d=132.0+(这个加号做为连接符)abcdef=132.0abcdef
2by+sh+num+ch=115+str(当数字与字符串进行+时,这个加号做为连接符并把结果转换成String型)115abcdef+8.0f=115abcdef8.0+9.0=115abcdef8.09.0
3也是同样的道理
其它好理解,+'a'实际上是求ASCII值
2.3数值型+String=String隐式转换
(JAVA自动进行类型转换),两边中有一个是字符串的时候进行字符串拼接操作。JAVA的同级运算符的执行顺序是从左到右。你的代码的具体运行的过程如lzj34(缘来如此) 所写。
最后输出的时候使用toString()方法
这样就不用想得那么复杂了