Page 68 - CA_Blue( J )_Class10
P. 68

Explanation of the output:

                            1.    (a>b && b>c)                           4.     (a<b || b>=c)
                             Ans:  (10>30 && 30>25)                      Ans: (10<30 || 30>=25)
                                  (false && true)                              (true && true)
                                  false                                        true
                            2.    (a<b && b>=c)                          5.    !((a+b)>c)
                            Ans: (10<30 && 30>=25)                       Ans: !((10+30)>25)
                                  (true && true)                               !(40>25)
                                  true                                         false
                            3.    (a>b || b>c)                           6.    !(c>a && a<b)
                             Ans:  (10>30 || 30>25)                      Ans: !(25>10 && 10<30)
                                  (false || true)                              !(true && true)
                                  true                                         !(true)
                                                                               false

              4.3.4 Assignment Operators
              Assignment operators are used to assign values to the operands. One of the commonly used assignment operators is
              =. It assigns a value on the right-hand side to the operand on the left-hand side. For example:
                  int a = 5;
              This operator can also be used with the arithmetic operators to form the shorthand assignment operators. These
              shorthand operators provide a short way to assign an expression to a variable. These are also called special compound
              assignment operators.

              For example:
                  int a = 5;
                  a = a + 10;
              Using shorthand operator can be written as a+= 10. Java provides the following shorthand operators:

                                                                                         Example
                  Operator                        Description                                               Output
                                                                                      a = 10 and b = 5
                              It assigns the result to the operand on the left-hand side
                     - =      after performing the subtraction operation.                 a - = b            a = 5

                              It assigns the result to the operand on the left-hand side
                     +=       after performing the addition operation.                    a += b            a = 15

                              It assigns the result to the operand on the left-hand side
                     /=       after performing the division operation.                    a /= b             a = 2

                              It assigns the remainder to the operator present on the
                    %=        left-hand side after performing the division operation.     a %= b             a = 0

                              It returns the result to the operand present on the left-
                     *=       hand side after performing the multiplication operation.    a *= b            a = 50



                     Note: The == operator is not an assignment operator. It is a relational operator used to check the
                     equality of two operands.







                6666  Touchpad Computer Applications-X
   63   64   65   66   67   68   69   70   71   72   73