byte short int long
floot double
char 虽然是字符,但是即使unico编码中的一个十进制整数,可以当做整数对待
boolean 不能和其他其他七种类型进行转换 true false
转换规则
容量小的转容量大的
byte 1字节 127 -- short 2字节
容量大的转容量小的
int 4字节 129 -- byte 1字节
floot4字节,但是由于小鼠的二进制存储与整数二进制存储结构不同,
4字节floot大于4字节的int,大于8字节的long
byte->short->char->int->long->->float->double
public class Demo {
public static void main(String[] args) {
//容量小的转容量大的 可以直接而进行转换
byte a = 127;
int b = a;
long c = b;
float d = c;
//容量大的转容量小的
//大转小:出现溢出
int m = 258;//2 658 --> -110
byte n = (byte)m;//int --> byte 编译器不能通过
System.out.println(n);
float x = 10.5f;
//大转小:精度损失
long y = (long)x;//10
System.out.println(y);
char z = 'a';// char也是可以参与转换
int zc = z;
byte aa = 10;
byte bb = 10;
byte cc = (byte)(aa+bb);// byte short char 在混合运算时,都会上升为int
float dd = x + m + a;//混合运算时小类型默认都会转为最大的类型
double xx = x + m + a + 5.5;
System.out.println(xx);
System.out.println(dd);
}
}