Page 61 - CA_Blue( J )_Class10
P. 61

System.out.println(original_result + " + 8 = " + result);

                         original_result = result;
                         result = result % 7;
                         // result is now 3
                         System.out.println(original_result + " % 7 = " + result);

                     }
                 }
                 Output:
                 1 + 2 = 3
                 3 - 1 = 2

                 2 * 2 = 4
                 4 / 2 = 2
                 2 + 8 = 10

                 10 % 7 = 3

                 Unary Plus (+) Operator
                 The unary plus (+) operator works only on one operand. The output is the same value of the operand which is either
                 an integer literal or a real literal. The result of the unary plus operator may be positive or negative depending on the
                 values.
                 For examples:
                 •  If int i = -20 then
                   +(-20) = -20
                 •  If double i = 10 then
                   +(10)  = 10

                 Unary Minus (-) Operator
                 The unary minus (-) operator works only on one operand. The output is the same value of the operand which is either
                 an integer literal or a real literal. The result of the unary minus operator may be positive or negative depending on the
                 values. For examples:
                 •  If int i = -20 then
                   -(-20) = +20
                 •  If int i = 20.5 then
                   -(20.5) = -20.5

                 Unary Increment (++) Operator
                 The unary increment (++) operator works only on one operand. The original value of the variable is increased by 1 after
                 the execution of this operator. It can work only on variables and identifiers which may either contain an integer literal
                 or a real literal. The result of the increment operator may be positive or negative.  For examples:
                 •  If int a = 20 and b = 4 then
                   ++a = 21
                   ++b = 5
                   Hence, the output is same as a = a + 1 or b = b + 1.
                 •  If int i = -20 then
                   ++i = -19



                                                                                                                       59
                                                                                                      Operators in Java   59
   56   57   58   59   60   61   62   63   64   65   66