首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

向大侠们求解.该如何解决

2012-09-28 
向大侠们求解.public class Example4 {public static void main(String args[]){double db 123.923dflo

向大侠们求解.
public class Example4 {
public static void main(String args[]){

double db = 123.923d;
float f = (float)db;
long l = (long)db;
int i = (int)db;
short s = (short)db;
byte b = (byte)db;
System.out.print("d = " + db + "; f = " + f + "; l = " + l);
System.out.print("; i = " + i + "; s = " + s + "; b = " + b);
db = 5127.87d;
b = (byte)db;
System.out.print("; d = " + db + "; b = " + b);
//为啥b等于7呢?
}

}
为啥输出后b的结果是7呢?

[解决办法]
db先转换成int,5127;
二进制为1010000000111;
强转成Byte,取低八位,0000111;
十进制就是7.

热点排行