Java: Logical Operators
Operators
Java provides quite a variety of operators which come in handy to the programmer for the manipulation of variables. In this page we are going to discuss about Logical Operator in Java.
The operators in java are as follows:
Arithmetic Operators
Relational Operators
Bitwise Operators
Logical Operators
Assignment Operators
Miscellaneous Operators
Relational Operators
Bitwise Operators
Logical Operators
Assignment Operators
Miscellaneous 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
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment