











Java: Logical Operators


Operators
Java provides quite a variety of operators which come in handy to the programmer for the manipulation of variables.
The operators in java are as follows:
- Arithmetic Operators
- Relational Operators
- Bitwise Operators
- Logical Operators
- Assignment Operators
Logical Operators
Logical operators are mainly used to control program flow. They allow a program to make a decision based on multiple conditions.
Operator | Functionality | Syntax |
&&(Logical AND) | It returns true if both statements are true | a && b |
||(Logical OR) | It returns true if one of the statements is true | a || b |
!(Logical NOT) | It reverses the result, returns false if the result is true | !(a == b) |
Syntax with Example
Run
public class Main { public static void main(String args[]) { boolean a = true; boolean b = false; System.out.println("a && b = " + (a&&b)); System.out.println("a || b = " + (a||b) ); System.out.println("!(a && b) = " + !(a && b)); } }
Output
a && b= false
a || b= true
!(a && b)= true
Login/Signup to comment