1.数据类型
a.
布尔类型:1位:true or false
byte:一字节8位 -128~127
short:两字节 -32768~32767
int:四字节 -2147483648~2147483647
long:八字节 -9223372036854775808-9223372036854775807
注释:一字节等于一位;
b.这些类型的精度从低到高的排列顺序为:byte->short->int(char)->long->float->double
2.两种提升精度的转换
a.隐式转换
public class ImplicitConversion{
public static void main(String[] args){
byte mbyte=127;
int mint=150;
float mfloat=452.12f;
char mchar=10;
double mdouble=45.46546;
System.out.println("byte型与float型运算结果:"+(mbyte+mfloat));
System.out.println("byte型与int型运算结果:"+(mbyte*mint));
System.out.println("byte型与char型运算结果:"+(mbyte/mchar));
System.out.println("double型与char型运算结果:"+(mdouble+mchar));
}
}
b.显示转换
public class ExplicitConversion{
public static void main(String[] args){
int a=(int)45.23;
long b=(long)456.6F;
char c=(char)97.14;
System.out.println("45.23强制转换成int:"+a);
System.out.println("456.6F强制转换long:"+b);
System.out.println("97.14强制转换成char:"+c);
}
}