public class 测试
{
public static void main(String[] args){
//编译报错,因为1000已经超出范围了
//byte b1 = 1000;
//可以
byte b2 = 20;
//可以
short s = 1000;
//可以
int c = 1000;
//可以
long d = c;
//编译报错
//int e = d;
//可以
int f = 10 / 3;
//可以
long g = 10;
//编译报错
//int h = g / 3;
//可以
long m = g / 3;
//编译报错
//byte x = (byte)g / 3;
//可以
short y = (short)(g / 3);
//可以
short i = 10;
//可以
byte j = 5;
//编译报错
//short k = i + j;
//可以
int n = i + j;
//可以
char cc = 'a';
System.out.println(cc); // a
System.out.println((byte)cc); //97
// cc 会自动转换成int类型
int c = cc + 100;
System.out.println(c); //197
}
}
基本数据转换规则
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章