Files
javaSE260715/day02/src/com/inmind/yunsuan02/Demo11.java

43 lines
1.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}
}