0
Can explain about NOT(!) Logical operator with example?
2 odpowiedzi
+ 2
not (!) is just the oposite.
example
true = true
false = false
!true = false
!false = true
when you use it on an statement:
if (7 != 6)
it will return true because 7 is not equal to 6.
0
Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.
public class Test {
public static void main(String args[]) {
int num1 = 3;
int num2 = 5;
//num1 == num2 will return false, then use ! the result will be true
//will print in console num1 not equal num2
if ( !(num1 == num2) ){
System.out.println("num1 not equal num2");
}//end if
else{
System.out.println("num1 equal num2");
}//end else
}//end main
}//end class test
I hope I helped you.