自动类型提升
package com.ithema.spedkey;
public class demo5 {
public static void main(String[] args) {
byte i = 10;
byte j = 20;
//byte v = i + j; // bug
int v = i + j;
System.out.println(v);
}
}
强制类型转换
强制类型转换,可能导致数据溢出丢失,浮点类型只保留整数部分。
package com.ithema.spedkey;
public class demo5 {
public static void main(String[] args) {
byte i = 10;
byte j = 20;
//byte v = i + j; // bug
int v = i + j;
System.out.println(v);
int a = 20;
byte b = (byte) a;
System.out.println(a);
System.out.println(b);
int k = 15000;
byte m = (byte) k;
System.out.println(k);
System.out.println(m);
double sf = 99.9;
int si = (int) sf;
System.out.println(si);
int sss = (int) 77.77;
System.out.println(sss);
}
}