逻辑运算符

package operator;

public class Demo05 {
//逻辑运算符
public static void main(String[] args) {
boolean a = true;
boolean b = false;

System.out.println("a && b:"+(a&&b));//逻辑与运算,真真才真
System.out.println("a || b:"+(a||b));//或运算,有真则真
System.out.println("!(a && b):"+!(a&&b));//真则假 假则真

//短路运算
//:如果为假 则后面不会执行
// eg
int c = 4;
boolean d = (c<4)&&(++c<10);
System.out.println(c);
System.out.println(d);

}
}
posted @ 2021-04-21 14:33  杨得体  阅读(60)  评论(0)    收藏  举报