1bit表示1位, 1Byte表示一个字节1B=8b。 1024B=1KB 1024KB=1M 1024M=1G.
byte,short,char-> int -> long-> float ->double
(转换后的类型)变量名 高-->低
System.out.println((int)22.5); //23
System.out.println((int)-12.13f); //-12
低-->高
int i = 128;
double a = i;
System.out.println(i); //128
System.out.println(a); //128.0
注意点:
//JDK7的新特性,数字之间可以用下划线分割
int money = 10_0000_0000;
System.out.println(money); //1000000000
int years = 20;
int total = money*years; //-1474836480,计算的时候溢出了
long total2 = money*years; //默认是int,转换之前已经存在溢出问题
System.out.println(total2); //-1474836480
long total3 = money*((long)years); //先把一个数转换为long
System.out.println(total3); //20000000000
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有