Java: Logical Operators

Logical Operator

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.

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

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription