[go: up one dir, main page]

0% found this document useful (0 votes)
10 views2 pages

Logical Operator

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Logical Operator

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

6)Logical Operator(&&,||,!

) :
=============================
Java Logical Operators :

Logical operators are used to check whether an expression is true or false. They
are used in decision making.

Operator Example Meaning


&& (Logical AND) expression1 && expression2 true only if both expression1
and expression2 are true
|| (Logical OR) expression1 || expression2 true if either expression1
or expression2 is true
! (Logical NOT) !expression true if expression is false
and vice versa

1)Logical AND Operator (&&):

expression1 Expression2 Result

true true true


false true false
true false false
false false false

2)Logical OR Operator(||):

expression1 Expression2 Result

true true true


false true true
true false true
false false false

3)Logical NOT Operator(!):

expression result

true false
false true

Example :

package typesOfOperator;

public class LogicalOperators {

public static void main(String[] args) {

int a = 10;
int b = 20;

System.out.println("Logical AND operator ");


System.out.println((a < b) && (a < b));
System.out.println((a < b) && (a > b));
System.out.println((a > b) && (a < b));
System.out.println((a > b) && (a > b));

System.out.println("Logical OR operator ");

System.out.println((a < b) || (a < b));


System.out.println((a < b) || (a > b));
System.out.println((a > b) || (a < b));
System.out.println((a > b) || (a > b));

System.out.println("Logical NOT Operator");

System.out.println(!(a < b));

}
}

You might also like