String字符串“+”号连接基本类型,返回值为什么进行了数字运算?
在learnJava网站上学习,练习String字符串
Exercise
造不同的基本类型数据. 然后放入String字符串中打印在屏幕上: H3110 w0r1d 2.0 true
我的代码:
public class Main {
public static void main(String[] args) {
char a = 'H';
int b = 3110;
char c = ' ';
char d ='w';
int e =0;
String f = "rld";
float g =(float)2.0;
boolean h = true;
String output = a+b+c+d+e+f+c+g+c+h;
System.out.println(output);
}
}
得到结果:3333rld 2.0 true
请帮我解释一下是为什么呢?
把char a 改成 String a,得到想要的结果
请帮我解释一下是为什么呢?