企业网站可信认证必须做吗,网站程序代码,在上海注册公司有什么好处,设计制作活动/*
目的#xff1a;测试变量的运算方式
结果#xff1a;byte a, b, c;a bc;或者 a b10形如这种形式的算式#xff0c; 等式的右边的运算结果默认的都是int型的#xff01;因为等式右边有变量#xff0c; 编译器无法确定变量的内容#xff0c;因为它是变量#xff01;所… /*
目的测试变量的运算方式
结果byte a, b, c;a bc;或者 a b10形如这种形式的算式 等式的右边的运算结果默认的都是int型的因为等式右边有变量 编译器无法确定变量的内容因为它是变量所以相加之后得到的int再默认强制转换成byte可能会损失精度.而形如 a45这种常量的赋值虽然 4 和 5 都默认的是int 但都是常量它们的值是确定的所以如果 45的值超过了byte的最大值的范围 那就会编译出错!(也就是等式右边都是常量运算编译器是可以判断的!)形如 byte a 9 b12;或者 ab; a10; 这样的赋值运算编译器底层都是做了强制转换运算的!也就是说 ab 等价于 a (byte)(ab); 而不是 a ab
*/public class VarDemo{public static void main(String args[]){StringBuffer str new StringBuffer(a);String newStr new String(str.append(1123));System.out.println(str.append(new myClass()));//这样写编译就是对的了!whyint a, b, c;b 10;c 14;a bc;int a1;byte b1, c1;b1 Byte.MAX_VALUE;c1 34;a1 b1c1; System.out.println(b1 a1);/*这样写是编译错的whybyte a3;byte b3;b3 12;a3 b3 6; System.out.println(b3 a3);*/ /*这样写是编译却是对的whybyte a34;byte b3;b3 12;a3 b3; System.out.println(b3 a3);*/ /*这样写编译是错的whybyte av100200;*//*这样写编译就是对的了whybyte a1;a145;*//*这样写编译是错的why? byte a1;byte b1, c1;b1Byte.MAX_VALUE;c134;a1b1c1;*//*这样写是编译错的whyshort a2, b2, c2;b210;c234;a2b2c2;*/}
}class myClass{int x;String str;public myClass(){x4234;str new String(hujunzheng);}public String toString(){return x str;}
}转载于:https://www.cnblogs.com/hujunzheng/p/3871945.html