JAVA基本数据类型之自动提升。
//数据类型自动提升
byte b1=1,b2=2,b;
b=b1+b2;//错误,b1+b2经过加法之后自动提升为int类型
System.out.println(t.getType(b1+b2));
//损失精度
byte b = (byte) 300;
System.out.println(b);
300原码:......1 0010 1100
byte类型:0010 1100
b的结果是44
字符串
unicode码表:
'a' 97
'A' 65
'0' 48
字符、字符串、整数相加
//字符串和其他数据做"+",不是+是连接符
System.out.println("hello"+'a'+1);
System.out.println('a'+1+"hello");
System.out.println("5+5="+5+5);
System.out.println(5+5+"5+5=");
结果:
helloa1
98hello
5+5=55
105+5=