day02--运算符_逻辑运算符和短路效果
This commit is contained in:
@@ -0,0 +1,33 @@
|
|||||||
|
package com.inmind.operator02;
|
||||||
|
/*
|
||||||
|
运算符_逻辑运算符
|
||||||
|
&& : 双与 短路与 并且
|
||||||
|
|| :双或 短路或 或者
|
||||||
|
! : 非 取反
|
||||||
|
|
||||||
|
短路效果:双与与双或的短路效果(只要已经有确定的结果,就不要做多余的操作)
|
||||||
|
*/
|
||||||
|
public class Demo11 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//双与:一假即假(并且)
|
||||||
|
System.out.println(true&&true);//true
|
||||||
|
System.out.println(true&&false);//false
|
||||||
|
System.out.println(false&&false);//false
|
||||||
|
|
||||||
|
//双或:一真即真
|
||||||
|
System.out.println(true||true);//true
|
||||||
|
System.out.println(true||false);//true
|
||||||
|
System.out.println(false||true);//true
|
||||||
|
System.out.println(false||false);//false
|
||||||
|
//非:取反
|
||||||
|
System.out.println(!false);//true
|
||||||
|
System.out.println(!!false);//false
|
||||||
|
|
||||||
|
System.out.println("------------------------------");
|
||||||
|
int a = 10;
|
||||||
|
int b = 20;
|
||||||
|
System.out.println((++a > 10) || (++b > 20));//true
|
||||||
|
System.out.println(a);//11
|
||||||
|
System.out.println(b);//20
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user