Computer Science

Explain Logical operator with an example.

Java Operators

156 Likes

Answer

Logical operators operate on boolean expressions to combine the results of these boolean expression into a single boolean value.

Example:

int a = 7;  
int b = 10;  
boolean c = a < b && a % 2 == 0;

Here, the result of first boolean expression a < b is true and the result of second boolean expression a % 2 is false. The logical AND operator ( && ) combines these true and false boolean values and gives a resultant boolean value as false. So, boolean variable c becomes false.

Answered By

79 Likes


Related Questions