Page 99 - 2617_JSSPS_C-6
P. 99

Assignment Operators

                 Assignment  operators are  used  to  assign  values  to  operands.  One  of  the  most commonly  used
                 assignment operators is equal (=). This operator can also be used with arithmetic operators to make
                 the shorthand assignment operators. The shorthand assignment operators perform calculations and
                 assign the result to the variable present on the left hand side of the operator.

                                                                                                Example
                  Operator                       Description                       Syntax                      Output
                                                                                             (int a = 10, b = 2)
                              Returns the  result to the  operand  present  on                    a += b        a = 12
                     +=       the left hand side after performing the addition      a += b
                              operation.                                                          a += 5        a = 15
                              Returns the result to the operand present on the                    a -= b         a = 8
                      -=      left hand side after performing the subtraction       a -= b
                              operation.                                                          a -= 5         a = 5
                              Returns the result to the operand present on the                    a *= b        a = 20
                     *=       left hand side after performing the multiplication   a *= b
                              operation.                                                          a *= 5        a = 50

                              Returns the  result to the  operand  present  on                    a /= b         a = 5
                      /=      the  left  hand  side  after performing  the  division   a /= b
                              operation.                                                          a /= 5         a = 2

                              Returns  the  remainder to  the  operator present                  a %= b          a = 0
                     %=       on the left hand side after performing the division   a %= b
                              operation.                                                         a %= 6          a = 4



                          Topic Flashback                                                  21 st  Century
                                                                                               Skills  #Digital Literacy
                        Name any three types of literals










                            Quick Quiz


                  1.  Which of the following is not a Unary operator?

                             a. >=                                         b. ++

                  2.  Which of the following operators are used to combine multiple conditions and evaluate them?

                             a. Logical Operator                           b. Relational Operator










                                                                              Introduction to Programming in Java   97
   94   95   96   97   98   99   100   101   102   103   104