English

Explain the following operator with an example program: Logical Operator

Advertisements

Question

Explain the following operator with an example program:

Logical Operator

Code Writing
Explain
Advertisements

Solution

A Logical Operator in Java is used to combine or reverse Boolean expressions and returns a Boolean value, either true or false.

The logical operators in Java are Logical AND (&&), Logical OR (||) and Logical NOT (!).

Example:

class LogicalOperator
{
    public static void main(String[] args)
    {
        int a = 10, b = 20;
        System.out.println((a < b) && (a > 5));
        System.out.println((a > b) || (a < 15));
        System.out.println(!(a < b));
    }
}

Output:

true
true
false
shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 132]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 6 Variables and Expressions
EXERCISE | Q 31. (c) | Page 132
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×