You are here: Home / Topics / Boolean Logical Operator Example in Java

Boolean Logical Operator Example in Java

Filed under: Java on 2023-08-11 19:26:51

//  Program to use Boolean Logical Operators ( &, |, ^, !  )

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


Output:

a = true
b = false
a|b = true
a&b = false
a^b = true
!a = false
!a&b|a&!b = true

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