Java - Logical Operators Example
Advertisements
The following simple example program demonstrates the logical operators. Copy and paste the following Java program in Test.java file and compile and run this program:
public class Test { public static void main(String args[]) { boolean a = true; boolean 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 the following result:
a && b = false a || b = true !(a && b) = true
java_basic_operators.htm
Advertisements