Not operator in java – Java Program on Logical NOT Operator

Not operator in java: In the previous article, we have discussed about Java Program on Logical OR Operator

In this article we will see the use of Logical operator NOT in Java programming language.

Java Program on Logical NOT Operator

Not operator java: Logical NOT operator is represented by ! symbol. It is a unary operator. It returns True when the condition/expression is false and returns False when the condition is true.

Syntax: !(expression)

Where,

  • ! is the operator
  • expression is the operand

Let’s see a program to understand it more clearly.

class Main
{
    public static void main(String[] args)
    {
        //initializing three integer variables a, b, c
        int a = 5, b = 8;
  
        //Printing values of a, b, c
        System.out.println("Value of a = " + a);
        System.out.println("Value of b = " + b);
  
        //using logical NOT operator
        //here the condition a>b is false
        //so NOT operator will return True
        System.out.println(!(a>b));
        //here the conditions is true 
        //so NOT operator will return False
        System.out.println(!(a<b));
    }
}
Output:

Value of a = 5
Value of b = 8
true
false

Are you wondering how to seek help from subject matter experts and learn the Java language? Go with these Basic Java Programming Examples and try to code all of them on your own then check with the exact code provided by expert programmers.

Related Java Programs: