输出hello word
byte(-128~127)、short、char、int(最多十位数且以2开头)、long、float、double(精度比float高)、boolean
强制类型转换,大的转小的不需要变,小的转大的需要强制类型转换,在转换的值得前面加基本数据类型
输出hello word
byte(-128~127)、short、char、int(最多十位数且以2开头)、long、float、double(精度比float高)、boolean
强制类型转换,大的转小的不需要变,小的转大的需要强制类型转换,在转换的值得前面加基本数据类型
public static void main(String[] args) {
//hello word
System.out.println("hello word !!!");
//强制类型转换
byte a=7;
byte b=9;
byte c=(byte)(a+b);
System.out.println("byte="+c);
System.out.println("----------");
short f=5;
short e=(short) (f+1);
System.out.println("short="+e);
System.out.println("----------------");
char g = 6;
char h = 8;
char i = '9';
System.out.println("char="+i);
System.out.println("----------");
//这个long类型比int大,所以不用类型转换
long j = 2l;
long k = 3l;
long l = j+k;
System.out.println("long="+l);
System.out.println("---------");
float m = 3.5f;
float n = 4.0f;
float o = m+n;
System.out.println("float="+o);
System.out.println("---------");
double p = 7.8;
double q = 8.9;
double r = p+q;
System.out.println("double="+r);
System.out.println("----------");
boolean s = false;
boolean t = true;
System.out.print(s+" "+t);
}
输出结果
hello word !!!
byte=16
short=6
char=9
long=5
float=7.5
double=16.7
false true