Logical operator & && | ||

Logical Operators:

& And: And, if false is false, only use the symbol to be true at the same time on both sides, the result is true

|Or: Or, when true is true, only use the left and right sides of the symbol to be false at the same time, the result is false

! Not: negate unary operator

^XOR: Same as false, different as true

&与&&

&: Whether the left side is true or false, the left and right are executed

&&: True on the left, execute on the right

public class L2{
    
    
	public static void main(String[] args){
    
    
	int x = 3;
	int y = 4;
	System.out.println(++x > 4 && y-- <5);
	System.out.println("x=" + x);
	System.out.println("y=" + y);
	
	System.out.println(x++ > 3 || ++y>5);
	System.out.println("x=" + x);
	System.out.println("y=" + y);
	}
}

Guess you like

Origin blog.csdn.net/qq_42073385/article/details/107700316