Page 66 - CA_Blue( J )_Class10
P. 66
Program 3: To use all the relational operators.
You will get the following output:
4.3.3 Logical Operators
Logical operators are used to check whether an expression is true or false. The output of the logical operators is
the outcome of different conditions as "true" or "false" depending on the relationship between the expressions.
There are three types of logical operators in Java. They are && (AND), || (OR) and ! (NOT). Let us learn about them
in detail.
The && Operator
The (&&) operator is known as the "Logical AND" operator. It is used for merging two conditions to make an expression.
If both the conditions in an expression satisfy, then the outcome of the && operator is true, otherwise false if any one
of the conditions does not satisfy. In Java programming, 0 (zero) denotes the false value and 1 (one) denotes the true
value. For example, if we take an expression (a>b && b>c), then the output will be:
Condition 1 Condition 2 Condition 1 && Condition 2
(a>b) (b>c) (a>b && b>c)
0 / false 0 / false 0 / false
0 / false 1 / true 0 / false
1 / true 0 / false 0 / false
1 / true 1 / true 1 / true
The || Operator
The (||) operator is known as the "Logical OR" operator. It is also used for merging two conditions to make an
expression. If any one of the conditions in the expression satisfies, then the outcome is true otherwise false.
6464 Touchpad Computer Applications-X

