Logical Operator
Logical operators only operate on Boolean operands and return a boolean data. There are 6 logical operators: &, |, &, | ,! And ^
Short Circuit logic operator Short-Circuit Logical Operators:
Public class Lesson04_6 {
02 public static void main (String [] args ){
03 int I = 5;
04 // short circuit and operator &. true is returned only when both the left and right expressions are true. If the first expression on the left is false, false is returned immediately, return immediately as if it was a short circuit, saving some unnecessary computing time.
05 boolean flag = (I <3) & (I <4 );
06 System. out. println (flag );
08 // short circuit or operator |. If either of the two expressions on the left or right is true, true is returned. If the first expression on the left is true, true is returned immediately, return immediately as if it was a short circuit, saving some unnecessary computing time.
09 flag = (I> 4) | (I> 3 );
10 System. out. println (flag );
11}
12}
Non-Short-Circuit logical operator Not Short-Circuit Operators:
View sourceprint? 01 public class Lesson04_6 {
02 public static void main (String [] args ){
03 int I = 5;
04 // non-short circuit and operator &. true is returned only when both the left and right expressions are true. Both expressions are calculated.
05 boolean flag = (I <3) & (I <4 );
06 System. out. println (flag );
08 // non-short circuit or operator |. If either of the two expressions is true, true is returned. Both expressions are calculated.
09 flag = (I> 4) | (I> 3 );
10 System. out. println (flag );
11}
12}
Author: "the sky of blue flowers"