You are here: Home / Topics / Program to explain Logical And ( & ) and Logical Short-circuit And ( && ) Operator in Java

Program to explain Logical And ( & ) and Logical Short-circuit And ( && ) Operator in Java

Filed under: Java

// Program to explain Logical And ( & ) and Logical Short-circuit And ( && ) Operator

class ShortCircuitAnd
{
public static void main(String args[ ]) 
{
 int a = 10, b = 20;
 
 if( (a < 5) && (++b < 10) )
 {
  System.out.println(" True ");
 }
 System.out.println(" b = " + b);
 
 if( (a < 5) & (++b < 10) )
 {
  System.out.println(" True ");
 }
 System.out.println(" b = " + b);
}
}


Output:

b = 20
b = 21

Categories