1、自动转换
目的类型比原来的类型大。两种类型是相互兼容的
byte->short
short->int
char->int
int->long
int->double
float->double
float 4字节 单精度 double 8字节 双精度
两个数中有一个位double类型,另一个也被转换成double类型,结果位double类型;
否则,两个数中有一个为float类型,另一个也被转换为float类型;
否则,如果两个操作数中有一个 long类型,另一个也被转换成loing类型
否则,两个数都转换为int类型。
2、强制类型转换
浮点型转换给整型;把小数点截掉,保留整数位
长的整数型赋给短的整型 :去位。
int 4个字节 32 位
byte 1个字节 8位
package day08;
public class TestChang {
public static void main(String[] agrs) {
/**double adouble=3.55555;
int aint =(int)adouble;
System.out.println("数值转换为"+aint);*/
int aint=257;
byte abyte=(byte)aint;
System.out.println("数值转换为"+abyte);
}
}