逻辑运算符

2019-06-25  本文已影响0人  南国铃子

-----2019/6/25

&,|,&&,||,!

&与&&,效果相同,运算机制不同

-------------------------------------------------------------------------------------------

class Demo2{

public static void main(String[] args){

int math = 88;

int chinese = 23;

//单号不智能,即使前面的结果能够决定最后的结果,但后面的表达式依旧要计算;

System.out.println((math >= 60) | (++chinese >= 60));

System.out.println(chinese);

                              //双||号智能,前面的结果决定最后的结果,后面的表达式无需计算;

System.out.println((math >= 60) || (++chinese >= 60));

System.out.println(chinese);

                                System.out.println((math >= 60) & (++chinese >= 60));

System.out.println(chinese);

//前面的表达式为true,后面为false,后面的表达式还需计算,如下:

                                int chinese1 = 23;

System.out.println((math >= 60) && (++chinese1 >= 60));

System.out.println(chinese1); //24

//前面的表达式能决定最后的结果,后面的表达式无需计算,如下:

                                int math1 = 45;

int chin = 23;

System.out.println((math1 >= 60) && (++chin >= 60));

System.out.println(chin);//23

boolean result = !true;

System.out.println(result);

System.out.println(!((math >= 60) || (++chinese >= 60)));

}

}

上一篇 下一篇

猜你喜欢

热点阅读