Page 97 - CA_Blue( J )_Class9
P. 97

Program 14     Write a program with all the arithmetical operators.

                   1  class use_of_arithmetical_operator

                   2  {
                   3       public static void main()

                   4       {
                   5           int a,b;

                   6           a=10;
                   7           b=4;

                   8           System.out.println("Application of arithmetic operators");
                   9           System.out.println("Addition: " +(a+b));

                  10           System.out.println("Subtraction: " +(a-b));
                  11           System.out.println("Multiplication: " +(a*b));

                  12           System.out.println("Division: " +(a/b));
                  13           System.out.println("Remainder: " +(a%b));

                  14           System.out.println("Unary + operator: " +(+a));
                  15           System.out.println("Unary - operator: " +(-a));
                  16           System.out.println("Unary increment operator: " +(++a));

                  17           System.out.println("Unary decrement operator: " +(--a));

                  18        }
                  19  }

                 You will get the following output:























                 Prefix Increment Operator
                 The prefix increment operator is written before the operand. First the operand’s value is increased by one 1, and
                 then it is used in the expression. For example:
                        int m=5, n;
                        n=++m *5;


                                                                                               Operators in Java   95
   92   93   94   95   96   97   98   99   100   101   102