public class TestConvert {
public static void main(String[] args) {
int i1 = 123;
int i2 = 456;
double d1 = (i1 + i2) * 1.2;//系统自动转换成double运算
float f1 = (float) d1;//必须加强制转换符
System.out.println(f1);
byte b1 = 1;
byte b2 = 2;
byte b3 = (byte)(b1 + b2);//系统将转换成int运算必须加转换符
System.out.println(b3);
double d2 = 1e200;
float f2 = (float)d2;//会产生溢出 可以编译但运行结果“无限infinity”
System.out.println(f2);
float f3 = 1.23f;//f必须加上
long l1 = 123;
long l2 = 300000000L;//L必须加上
float f = l1 + l2 + f3;//系统自动转换成float运算
long L = (long) f;//强制转换会去掉小数点后面的数
System.out.println(L);
}
}