类型转换
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
public class demo {
public static void main(String[] args) {
//类型转换
/*
低---------------------高
byte-short-char-int-long-float-double
运算中不同类型的数据先转化为同一类型再运算
1.不能对布尔值进行转换
2.不能把对象类型转换为不相干的类型
3.高容量转低容量强制转换,存在容量溢出,精确度不够
*/
// 强制转换 高--低
// 自动转换 低--高
int i = 128;
byte b = (byte) i; // 内存溢出(byte(-128-127))
System.out.println(b);
System.out.println(i);
int q = 128;
long w = q;
System.out.println(w);
//高转低案例
System.out.println((int)23.7);
char c = 'a';
int d = c+1;
int e = c;
System.out.println(c);
System.out.println(d);
System.out.println(e);
System.out.println((char)d);
int money = 1000000000;
int year = 20;
int have = money*year;//容量溢出
long have2 = money*((long)year);
System.out.println(have);
System.out.println(have2);
}
}

浙公网安备 33010602011771号