javacodex.com
Java Examples
Java Examples
memu home questions

Short Circuit Logical Operators

The && and || operators perform Conditional-AND and Conditional-OR operations on two boolean expressions. These operators exhibit "short-circuiting" behavior, which means that the second operand is evaluated only if needed.

Source: (ShortCircuit.java)

public class ShortCircuit {
   public static void main(String[] args) {
      boolean a = true && true;
      boolean b = true && false;
      boolean c = false && false;
      boolean d = true || true;
      boolean e = true || false;
      boolean f = false || false;
 
      System.out.println("a = " + a );
      System.out.println("b = " + b );
      System.out.println("c = " + c );
      System.out.println("d = " + d );
      System.out.println("e = " + e );
      System.out.println("f = " + f );
   }
}
 

Output:

# java ShortCircuit 
a = true
b = false
c = false
d = true
e = true
f = false

Contact: javacodex@yahoo.com