java数据类型转换,
分享于 点击 7748 次 点评:96
java数据类型转换,
java类型之间的转换:
首选是精度的顺序:byte.short.char<int<long<float<double
byte.short.char是一个层次的,相互之间不转换,但用时全部转换成int型
精度高的转换成精度低的时,要强制转化,否则不用
如:double i=1.0;
float j=(float)i;
double a=j;
有一些注意的:
float f=0.1f;是正确的
但是float f=0.1;错误
又如:
byte b1=1;
byte b2=2;
byte b3=b1+b2; 是错误的
要写成: byte b3=(byte)(b1+b2);
因为byte运用时,系统将byte转化成int型
相关文章
- 暂无相关文章
用户点评