Java Logical Operators in Conditions

Java Logical Operators in Conditions

Logical operators in Java are used to combine multiple conditions (boolean expressions). They help in making decisions during program execution.


List of Logical Operators

Operator Name Description Example
&& Logical AND True only if both conditions are true (a > b && a > c)
Logical OR
! Logical NOT Reverses the boolean value !(a > b)

1️⃣ Logical AND (&&)

Returns true only when both conditions are true.

Example:


 

📌 Output:

Eligible for job

2️⃣ Logical OR (||)

Returns true if at least one condition is true.

Example:


 

📌 Output:

Pass or Grace Marks Allowed

3️⃣ Logical NOT (!)

Reverses the result of the boolean condition.

Example:


 

📌 Output:

You can go outside

✔ Combining Logical Operators

You can combine multiple conditions using &&, ||, and !.


 


Short-Circuit Behavior

  • && stops checking if first condition is false

  • || stops checking if first condition is true

Example:


 


🧠 Summary

Operator Works When Result
&& Both conditions true True
! Opposite of condition True/False reversed

You may also like...