The logical NOT operator in Java is represented by !
. It negates the boolean value of its operand. Here's an example:
public class LogicalNotExample {
public static void main(String[] args) {
// Example boolean expression
boolean expressionResult = (5 > 3);
// Using logical NOT operator
boolean result = !expressionResult;
// Displaying the result
System.out.println("Result of logical NOT: " + result);
}
}
In this example, the expression (5 > 3)
evaluates to true
, and then the logical NOT operator negates it, resulting in false
. Feel free to run this Java program to see the output.