标签:
int a = 10; int b = a + (a = 5) + a + (a = 10); System.out.println(b);//b = 30
int i = 1; i = (i=i+(i+(i=2)+i)+i)+3; System.out.println(i);//i = 11
int a = 1; int b = 2; System.out.println((a = 3) + (b = 4) + a*b);//19
System.out.println(-11 % -7);//-4 注:模运算中,第一个操作数提供结果值的符号。第一个和第二个操作数的绝对值取模后作为结果值的绝对值问题5:
int i = 1; System.out.println(i+++i+++i+++i++);//10 注:1+2+3+4 = 10问题6:
int i = 1; System.out.println(i++ + ++i+i++ + ++i);//12 注:1+3+3+5 = 12问题7:
int i = 1; int j = i+++(i=1)+i+++(i=1)+i++; System.out.println(j);//j = 5 注:j = 1+1+1+1+1问题8:
int a = 10; int b = 10; double c = 10.0; System.out.println(a == b);//true System.out.println(a == c);//true问题9:
System.out.println(3.0*10 == 30.0);//true System.out.println(3.141*10 == 31.41);//true System.out.println(3.14*10 == 31.4);//false 注:3.14*10 = 31.400000000000002 System.out.println(3.1415*10 == 31.415);//false 注:3.1415*10 = 31.415000000000003问题10:
java会将范围在-128~+127(byte的范围)的数放在一个静态数组中缓存,所以仅仅要在此范围内的装箱指向的都是这个数组中的对象,而在此范围外的则需new Integer a = 128; Integer b = 128; Integer c = 127; Integer d = 127; System.out.println(a == b);//false System.out.println(c == d);//true问题11:
byte a = 1; // byte a = 128//报错。注意byte的范围为-128~127 byte b = 1; a = (byte) (a+1); b++; System.out.println(a==b);//true问题12:
System.out.println(true | false & false);//true 注:与运算比或运算优先级高问题13:
int a = 10;//0000 0000 0000 0000 0000 0000 0000 1010 System.out.println(a<<1);//10*2=20 System.out.println(a<<2);//10*2^2=10*4=40 System.out.println(a<<32);//10 左移32位(int的大小)之后。回归原来的值 System.out.println(a<<32L);//10 不会转型。右側操作数只提供左移位数 long b = 10L; System.out.println(b<<1);//20 System.out.println(b<<2);//40 System.out.println(b<<64);//10 long为8字节,64位。所以须要左移64位才干循环一圈回到原点 System.out.println(b<<64L);//10 byte c = 1; System.out.println(c<<1);//2 System.out.println(c<<2);//4 System.out.println(c<<8);//256 这里须要注意。c为byte类型,移位操作的操作数最小要求是int类型。byte会转为int System.out.println(c<<32);//1 能够把c当成int型
int a = 10; a = a<<10; a = a<<22; int b = 10; b = b<<32; System.out.println(a);//0 注:第一步左移10位,第二步移动的a并不是原始的a,而是a左移10位之后的a,这次左移22位之后把非零位移到边界之外了,补零之后值变为0 System.out.println(b);//10 回归原始的10问题15:
int a = 10; double b = 9.5; System.out.println(a>b ? a : b);//10.0 结果会转成double型 System.out.println(a>b ? 1 : false); //2 尽管boolean不能转成int,可是自己主动装箱之后能够转成object问题16:
int a = 1; a+=a+=a++; System.out.println(a);//3问题17:
int a = 1; a += 3L;//不报错 // a = a+3L;//报错,高类型转低类型 System.out.println(a); int b = 1; b += 3.5; //复杂的算术表达式,自己主动型高意愿变低型 System.out.println(b);//结果4代替4.5
标签:
原文地址:http://www.cnblogs.com/yxwkf/p/5040312.html