您的位置:首页 > 编程语言 > Java开发

13.java语言基础-基本类型的自动转换强制转换

2017-06-07 15:38 441 查看
/* 
       在8大数据类型转换中,Boolean类型不属于数值类型,不参与转换
       一般的.byte.short.char不参与转换类型
       我们直接把byte.short.char直接赋给int类型*/

 

//byte-short-int-long 自动转换

byte a =100; 
// byte 类型 
a 变量 
100字面量

System.out.println(a);
//打印当前变量a的值

short b = a;  
// short 类型  
b 变量 
a 变量

System.out.println(b);
//打印当前变量b的值

int c = b;

System.out.println(c);
//打印当前变量c的值

long d = c;

System.out.println(d);
//打印当前变量d的值

//byte-short-int-long 强制转换

int cc =(int)d;  
//long d 强制转换成
int类型

System.out.println(cc);

short bb = (short)d;
//long d 强制转换成 short类型

System.out.println(bb);

byte aa = (byte)d;  
//long d 强制转换成 byte类型

System.out.println(aa);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐