短路运算

当前面为“false”时,后面的将不执行,只有“true”才会运行,这就叫短路运算。

如:

public class day0928 {
    public static void main(String[]args){
        int c1 = 113;
        boolean x=(c1<100)&&(c1++<120);//由于(c1<100)不成立为false,所以(c1++<120)就不运行
        System.out.println(c1);//Flase
        System.out.println(x);//由于(c1++<120)没有运算,所以c1没有自增
    }
}

运行结果:

113

false

posted @ 2021-09-29 23:14  光明^^龙  阅读(49)  评论(0编辑  收藏  举报