packageoperator;publicclassDemo05{publicstaticvoidmain(String[] args){boolean a =false;boolean b =true;System.out.println("a && b: "+(a && b));//false System.out.println("a || b: "+(a || b));//trueSystem.out.println("!(a && b): "+!(a && b));//true//短路原则int c =10;boolean d =(c >100)&&(c ++<100);System.out.println(c);//10System.out.println(d);//false}}
位运算
packageoperator;publicclassDemo06{publicstaticvoidmain(String[] args){/*
A = 0011 1100
B = 0000 1101
A & B = 0000 1100
A | B = 0011 1101
A ^ B = 0011 0001
~B = 1111 0010
*//*
2 ^ 8 = 2*2*2*2*2*2*2*2
0000 0001 1
0000 0010 2
0000 0100 4
0000 1000 8
//效率很高
<< 左移 = *2
>> 右移 = /2
*/}}
注意
packageoperator;publicclassDemo07{publicstaticvoidmain(String[] args){int a =10;int b =20;
a += b;
a -= b;System.out.println(a);//10//字符串的连接 +号的任意一边为字符串 则输出就为字符串System.out.println(a + b);//数字20System.out.println(""+ a + b);//字符串1020System.out.println(a + b +"");//字符串30}}
三元运算符
packageoperator;publicclassDemo08{publicstaticvoidmain(String[] args){//三元运算符//x ? y : z 如果x为真 则结果为y 否则为zint score =80;String type =(score >90)?"优秀":"不优秀";System.out.println(type);//不优秀}}