javacodex.com
Java Examples
Java Examples
memu home questions

Logical Operators

This java program example demonstrates the use of Logical Operators.

Source: (LogicalOperators.java)

public class LogicalOperators {
   public static void main(String[] args) {
 
      byte a = 0b1111 & 0b1000;
      byte b = 0b0111 | 0b1001;
      byte c = 0b0101 ^ 0b0100;
 
      boolean d = ! true;
      boolean e = ! false;
 
      System.out.println("a = " + a );
      System.out.println("b = " + b );
      System.out.println("c = " + c );
 
      System.out.println("d = " + d );
      System.out.println("e = " + e );
   }
}
 

Output:

# java LogicalOperators 
a = 8
b = 15
c = 1
d = false
e = true

Contact: javacodex@yahoo.com