java数据类型转换

 1 public class ShuJuZhuanHuan {
 2     public static void main(String[] args) {
 3         int a1=123;
 4         int a2=456;
 5         double b1=(a1+a2)*1.2;//系统将转换为double型运算
 6         float c1=(float)((a1+a2)*1.2);//需要加强制转换符
 7         byte d1=1;
 8         byte d2=2;
 9         byte d3=(byte)(d1+d2);//系统将转换为int型运算,需要强制转换符
10         double b2=1e200;
11         float c2=(float)b2;//会产生溢出
12         System.out.println(c2);
13         float c3=1.23f;//必须加f
14         long e1=123;
15         long e2=3000000000000L;//必须加L
16         float c4 =e1+e2+c3;//系统将转换为float型计算
17         long e=(long)c4;//强制转换会舍去小数部分(不是四舍五入)
18     }
19 }
数据转换
1         float f1=0.1;//有问题加F或者强制转换
2         long L1=8888888888;//需要加L
3         i=1/10;//结果为0
4         i=(i*0.1);//double 转换为int 会丢失
易错

程序格式:

a:大括号对齐

b:Tab/Shift+Tab

c:程序块之间加空行

d:并排语句之间加空格

e:运算符两侧加空格

f:{ 前面有空格

g:成对编程

扫描二维码关注公众号,回复: 105588 查看本文章

猜你喜欢

转载自www.cnblogs.com/jinmoon/p/8985790.html