day02-运算符-逻辑运算符

This commit is contained in:
2026-01-14 14:12:13 +08:00
parent a666a0a0f4
commit 01dd014916
2 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
package com.inmind.yunsuanfu02;
/*
运算符_比较运算符
==,>,< ,>=,<=,!=
*/
public class Demo08 {
public static void main(String[] args) {
System.out.println(1==1);//true
System.out.println(1<2);//true
System.out.println(3>4);//false
System.out.println(3<=4);//true
System.out.println(3>=4);//false
System.out.println(3!=4);//true
}
}

View File

@@ -0,0 +1,41 @@
package com.inmind.yunsuanfu02;
/*
运算符_逻辑运算符
&& : 双与 短路与 并且
|| :双或 短路与 或者
! : 非 取反
注意:逻辑运算符经常与比较运算符结合使用!!!
短路效果:双与与双或的短路效果(只要已经有确定的结果,就不要做多余的操作)
*/
public class Demo09 {
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("--------------------------");
//判断一个小学生是否得了100
int math = 100;
int chinese = 99;
System.out.println((math == 100)||(chinese==100));//false
System.out.println("-----------以下是短路效果-----------");
int i = 10;
int j = 20;
//短路效果:双与与双或的短路效果(只要已经有确定的结果,就不要做多余的操作)
System.out.println(i<j && i++ > ++j);//false
System.out.println(i);//11
System.out.println(j);//21
}
}