No announcement
 

Logical Operators

Logical operators are used to perform logical AND, OR and NOT operation.

  1. Logical AND
    This operator returns true when both the specified conditions are true.
  2. Logical OR
    This operator returns true when one of the conditions is true.
  3. Logical NOT
    This is a unary operator and return true when the condition is false.

Example:

LogicalOperatorsDemo.java

package com.codingnous.tutorial;

public class LogicalOperatorsDemo {

	public static void main(String[] args) {

		int value1 = 975, value2 = 198, sum = 1200;

		System.out.println("Logical AND Operation: " + (value1 > sum && value2 < sum));
		System.out.println("Logical OR Operation : " + (value1 > sum || value2 < sum));
		System.out.println("Logical NOT Operation: " + !(value1 > sum || value2 < sum));
	}

}

Output
Logical AND Operation: false Logical OR Operation : true Logical NOT Operation: false