javacodex.com
Java Examples
Java Examples
memu home questions

Logical Short Circuit

This java program example demonstrates the use of short circuit logical operators.

The && and || operators "short-circuit", meaning they don't evaluate the right hand side if it isn't necessary.

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:

va ShortCircuit 
a = true
b = false
c = false
d = true
e = true
f = false

Contact: javacodex@yahoo.com