Java-Boolean Logical Operators

Boolean Logical Operators

The Boolean logical operators are used when we want to form compound conditions by combining two or more relations.

Operator Meaning
| Logical OR
& Logical AND
^ Logical XOR
! Logical NOT

The following table shows the effect of each logical operation :

A B A | B A & B A ^ B  ! A
True False True False True False
False True True False True True
True True True True False False
False False False False False True

Program

2

Program Source

class Javaapp {

    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;
        System.out.println("c = "+c);
        System.out.println("d = "+d);
        System.out.println("e = "+e);
        System.out.println("f = "+f);
    }
}

Leave a Comment