MCQ Single Best Answer Easy

QWhich logical operator is used for logical NOT in Java?

ID: #20146 Logical Operators in Java 125 views
Question Info
#20146Q ID
EasyDifficulty
Logical Operators in JavaTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A !
  • B &&
  • C ||
  • D ^
Correct Answer: Option A

Explanation

The logical NOT operator (!) in Java is used to negate a boolean expression. It returns true if the expression is false and false if the expression is true.

The logical NOT operator in Java is represented by the exclamation mark (!). It negates the boolean value of its operand. Here's an example:


public class LogicalNotExample {
    public static void main(String[] args) {
        // Example boolean value
        boolean x = true;

        // Using logical NOT operator
        boolean result = !x;

        // Displaying the result
        System.out.println("Result of logical NOT: " + result);
    }
}

In this example, if x is initially true, the logical NOT operation (!x) will result in false. If x is initially false, the NOT operation will result in true. Feel free to run this Java program to see the output.

Share This Question

Challenge a friend or share with your study group.