//逻辑运算符 && 、||、!
boolean a=true;
boolean b=false;
System.out.println("a&&b: "+(a&&b));//输出false
System.out.println("a||b: "+(a||b));//输出true
System.out.println("!(a&&b): "+!(a&&b));//输出true
//逻辑运算存在短路机制,举例解释
int t=2;
int f=3;
System.out.println(t>3&&(f++)>2?"Gemin":"Chang");//输出Chang
System.out.println(f);//f=3,f并没有进行加一
//可以发现在t>3&&(f++)>3?"Gemin":"Chang"中,只进行了t>3?的判断,因为已经是false,false和任何情况相与都是false,
// 故(f++)>2?就不用执行
位运算符是基于底层进行运算,所以运算速度快,效率高
//位运算 &、|、^
//按位与、按位或、异或
//<< 左移 相当于乘二,效率高
//>> 右移 相当于除二,效率高
byte p1=1;//0000 0001
byte p2=2;//0000 0010
System.out.println(p1&p2);//输出0
System.out.println(p1|p2);//输出3
System.out.println(p1^p2);//输出3
//如何快速计算2^3
System.out.println(1<<3);
//三元运算符
//x?y:z
//如果x为true,则结果为y,否则为z
int score=80;
System.out.println(score>=60?"及格":"不及格");
int badscore=59;
System.out.println(badscore>=60?"及格":"不及格");
//关于字符串连接符 + ,String 只要在+号两端中有一段有字符串,那么会将两边的变量全转换为字符串再进行拼接
int c=10;
int d=20;
System.out.println(""+c+d);//输出“ 1020”说明c和f全被当成字符串来拼接
System.out.println(c+d+"");//输出“30 ”说明,正常计算a+b后将c+d的结果当成字符串与空字符串进行拼接
原文:https://www.cnblogs.com/gemin-chang/p/13692033.html