与或非

时间:2021-09-16 07:59:01   收藏:0   阅读:28

与或非

package operator;

public class Demo05 {
    public static void main(String[] args) {
        //    与(and)   或(or)   非(取反)
        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));//如果是假,则变为真,如果是真,则变成假

        //短路运算
        //例子
        int c=5;
        boolean d=(c<4)&&(c++<4);
        System.out.println(d);
        System.out.println(c);  //   输出为5 则(c++<4)未运行

    }
}

原文:https://www.cnblogs.com/yahhh/p/15265424.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!