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 on 2023-08-11 19:30:14

// 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

About Author:
V
Vinay Kumar     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.