10.运算符_比较运算符&&11.运算符_逻辑运算符和短路效果

This commit is contained in:
2025-12-24 10:55:03 +08:00
parent 1334bf4091
commit 01d0c683d3
2 changed files with 54 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package com.inmind;
/*
运算符_逻辑运算符
&& : 双与 短路与 并且
|| :双或 短路与 或者
! : 非 取反
短路效果:双与与双或的短路效果(只要已经有确定的结果,就不要做多余的操作)!!!!!
*/
public class Demo10 {
public static void main(String[] args) {
//双与:一假即假
System.out.println(true && true);//true
System.out.println(true && false);//false
System.out.println(false && true);//false右边不计算
//双或:一真即真
System.out.println(false || false);//falase
System.out.println(false || true);//true
System.out.println(true || false);//true右边不计算
System.out.println(!false);//true
System.out.println("-----------------------------------------------");
int i = 10;
System.out.println(i>5 && i++>10);//false
System.out.println(i);//11
int j = 20;
System.out.println(j++<21 && ++j<20);
System.out.println(j);
}
}