day02-运算符_逻辑运算符和短路效果

This commit is contained in:
2026-07-16 10:58:05 +08:00
parent ac0f748cb6
commit 2826fd011a

View File

@@ -0,0 +1,42 @@
package com.inmind.yunsuan02;
/**
逻辑运算符:
&& 短路与 并且
|| 短路或 或者
取反
注意:&& 和 ||其实是有短路效果的(也就是对应的结果已经确定,那么后面的代码不会执行!!!!
*/
public class Demo11 {
public static void main(String[] args) {
//双与 :一假即假
System.out.println(true&&true );//true
System.out.println(false&&true);//false
System.out.println(true&&false);//false
System.out.println(false&&false);//false
System.out.println("---------------");
//双或 :一真即真
System.out.println(true||true);//true
System.out.println(false||true);//true
System.out.println(true||false);//true
System.out.println(false||false);//false
System.out.println("---------------");
//! 取反
System.out.println(!false);//true
System.out.println(!true);//false
//常见的情况如下
int a = 88;
int b = 88;
System.out.println((a==100)&&(b==100));//true
//如果有一门是95分以上就带你去玩
System.out.println((a>=95)||(b>=95));//true
System.out.println("--------------------------------------");
int i = 10;
int j = 20;
System.out.println(--i<10 && j++>10);//true
System.out.println(i);//9
System.out.println(j);//21
}
}