运算符三(逻辑运算符)

public class Day05 {
public static void main(String[] args) {
//与(and) 或(or) 非(取反)
boolean a = true;
boolean b = false;

System.out.println("a && b"+(a&&b));//逻辑与运算:两个都为真,结果是true
System.out.println("a || b"+(a&&b));//逻辑与运算:一个都为真,结果是true
System.out.println("!(a && b)"+!(a&&b));//如果是真,则是false,如果是假,则是true


//短路运算
int c = 5;
boolean d = (c<4)&&(c++<4);// 短路的意思就是当&前面已经判定为假以后将不再执行后面的判断
System.out.println(d);//false
System.out.println(c);//5

}
}

posted @ 2021-08-07 11:16  幻协  阅读(34)  评论(0)    收藏  举报