-----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)));
}
}
网友评论