基本数据类型之间的运算规则:
byte、char、short -> int -> long -> float -> double
注意:byte、char、short这三种数据类型做运算时,结果为int型。
public static void main(String[] args) {
char one = 'a'; //97
char two = 'b'; //98
int three = 10;
String str = "hello";
System.out.println(one + three); //107
System.out.println(one + str); //ahello
System.out.println(three + str); //10hello
System.out.println(one + 2); //99
System.out.println(one + two); //195
}
运行结果:
char和int之间相加,char型会转换为int类型,最后结果为107.
char和char之间相加,最后结果也是int类型,最后结果为195.



