Précision Java de haut en bas: double-> float-> long-> int-> short-> char-> byte
public class Demo {
public static void main(String[] args) {
byte b = 127;
char c = 'Q';
short s = 23561;
int i =3333;
long l = 20000L;
float f = 3.1415f;
double d = 54.523;
System.out.println("========================\n低类型向高类型自动转换");
System.out.println("累加byte等于:" + b);
System.out.println("累加char等于:" + (b + c));
System.out.println("累加short等于:" + (b + c + s));
System.out.println("累加int等于:" + (b + c + s + i));
System.out.println("累加long等于:" + (b + c + s + i + l));
System.out.println("累加float等于:" + (b + c + s + i + l + f));
System.out.println("累加double等于:" + (b + c + s + i + l + f + d));
System.out.println("========================\n高类型向低类型强制转化(注意会有精度丢失问题)");
System.out.println("double——>float:" + (float)d);
System.out.println("float——>long:" + (long)f);
System.out.println("long——>int:" + (int)l);
System.out.println("int——>short:" + (short)i);
System.out.println("short——>char:" + (char)s);
System.out.println("char——>byte:" + (byte)c);
}
}