Demonstrate the boolean logical operators : Logical Operators « Operators « Java Tutorial






public class MainClass {
  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 & b) | (a & !b);
    boolean g = !a;
    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&b|a&!b = " + f);
    System.out.println("       !a = " + g);
  }
}
a = true
b = false
a|b = true
a&b = false
a^b = true
!a&b|a&!b = true
!a = false








3.7.Logical Operators
3.7.1.Boolean Logical Operators
3.7.2.The following table shows the effect of each logical operation
3.7.3.Logical operators in action
3.7.4.Demonstrate the boolean logical operators
3.7.5.Logical Operators
3.7.6.AND operator
3.7.7.&& versus &
3.7.8.Logical OR Operations
3.7.9.Boolean NOT Operations: applies to one boolean operand
3.7.10.Demonstrates short-circuiting behavior