Page 102 - CA_Blue( J )_Class9
P. 102

11          System.out.println("Answer of >= operator : "+(a>=b));
                    12          System.out.println("Answer of <= operator : "+(a<=b));

                    13      }
                    14  }

                            You will get the following output:             Explanation of the output:
                                                                            1. 7 == 11     :      false

                                                                            2. 7!=11       :      true
                                                                            3. 7>11        :      false

                                                                            4. 7<11        :      true
                                                                            5. 7>=11       :      false
                                                                            6. 7<=11       :      true


                  5.3.5 Logical Operators
                  These 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 conditions in the
                  expression. There are three types of logical operators in Java. They are && (AND), || (OR) and ! (NOT).

                  The && Operator
                  This operator is known as “AND” or “Logical AND” operator. The AND operator returns true only if all conditions
                  are true; otherwise conditions is false, the result will be false. In Java programming, 0 (zero) denotes a false value
                  and 1 (one) denotes a true value.
                  For example, if we take the 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
                  This operator is known as “OR” or “Logical OR” operator.  It is also used for comparing two conditions.  The
                  outcome of this operator is true if any one of the conditions in the expression satisfies; and the outcome is false
                  only if all the conditions are false. For example, if we consider the 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              1/ true

                                       1 / true                 0 / false             1/ true
                                       1 / true                 1 / true              1/ true




                   100    Touchpad Computer Applications-IX
   97   98   99   100   101   102   103   104   105   106   107