逻辑与或非

public class Demo13 {
public static void main(String[] args) {
//与(and) 或(or) 非(取反)
boolean a = true;
boolean b = false;
System.out.println("a && b :"+(b&&a));//逻辑与运算:全真则真
System.out.println("a || b :"+(b||a));//或:一真即真
System.out.println("!a && b :"+!(b&&a));
System.out.println("==============");
//短路运算
int c = 5;
boolean d = (c<4)&&(c++<4);
System.out.println(d);//根本没有执行(c++<4)
System.out.println(c);
}
}
输出:

a && b :false
a || b :true
!a && b :true
==============
false
5

Process finished with exit code 0

posted @ 2021-08-19 21:27  小风扇呜呜呜  阅读(78)  评论(0)    收藏  举报