与或非
逻辑运算符
package operator;
public class Demon05 {
public static void main(String[] args) {
boolean a = true;
boolean b = false;
System.out.println(b&&a);
System.out.println(b||a);
System.out.println(!(a&&b));
}
}
结果
false
true
true
前置条件:
与:运算的两个a、b类型结果都为true时,才会输出true,其他情况都是FALSE
或:运算的两个a、b类型结果只要有一个为true时,就会输出true
非:运算的结果相反
扩展:
int c = 4;
boolean d=(c<4)&&(c++<4);//c<4逻辑不成立
System.out.println(c);
System.out.println(d);
结果:
4
true
这里有短路的概念,当运算步骤中出现逻辑符的情况,会停止往下运算,直接输出结果