Copyright © tutorialspoint.com

Java Logical Operators Example

previous next


The following simple example program demonstrates the logical operators. Copy and paste following Java program in Test.java file and compile and run this program. :

class Test {
public static void main(String args[]) {
   int a = true;	
   int b = false;	

   System.out.println("a && b = " + (a&&b) );

   System.out.println("a || b = " + (a||b) );

   System.out.println("!(a && b) = " + !(a && b) );
}
} 

This would produce following result:

a && b = false
a || b = true
!(a && b) = true

previous next

Copyright © tutorialspoint.com