java中8种基本数据类型占的位数以及取值范围

java中有8种基本数据类型:byte、int、short、long、boolean、char、float、double
对应的类为:Byte、Int、Short、Long、Boolean、Charecter、Float、Double
其中:boolean是逻辑型,char是文本型,byte、short、int、long是整数型,float、double是浮点型

byte:1字节 -128~127
short:2字节 -2^15~2^15-1
int :4字节 -2^31~2^31-1
long:8字节 -2^63~2^63-1
boolean:1字节 true false(java中不能以0或非0代替)
float: 4字节 -3.403E38~3.403E38
double:8字节 -1.798E308~- 4.9E324
char:2字节  ’\u0000‘~' ’\uffff '(16进制的,换算过来即0~65535)

(1字节等于8位)



类型自动转换的规则:
 

容量小的数据类型可以自动转换为容量大的数据类型;


低级向高级是隐式类型转换,高级向低级必须强制类型转换,byte<char<short<int<long<float<double

猜你喜欢

转载自blog.csdn.net/youyou_go/article/details/80374512