42 lines
1.5 KiB
Java
42 lines
1.5 KiB
Java
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
|
|
}
|
|
}
|