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
true
false
shaalaa.com
Is there an error in this question or solution?
