In this java article, we will be covering "!" logical operator in Java. "!" logical operator makes TRUE return FALSE.
Lets look to syntax of "!" in Java.
int x = 1;
int y= 5;
if(!(x > y))
{
System.out.println("x > y OR x = 1");
}
else
{
System.out.println("else..");
}
Lets see it in Java code example.
In above example, we declared two variable and used "!" operator as logical NOT operation. If block executes if both is FALSE. Because "!" reverse it. To test it, we printed result with IF and ELSE blocks. In our example, "x" was smaller "y" and condition returned FALSE but "!" operator reversed it to TRUE. Therefore IF block has been executed rather ELSE.