Page 287 - CA_Blue( J )_Class9
P. 287

4          public static void main()
                   5          {

                   6              Scanner sc= new Scanner(System.in);
                   7              int num1,num2,sum,pro,diff,rem,ch; // Declaration of variable

                   8              double quo;
                   9              System.out.print("Enter 1st number : ");
                  10              num1=sc.nextInt();                           //Accepting value

                  11              System.out.print("Enter 2nd number : ");

                  12              num2=sc.nextInt();                           //Accepting value
                  13               System.out.print(" ********** \n 1 - sum \n 2 - Difference \n 3 -
                                    product \n 4 - Quotient \n 5 - Remainder \n Enter your choice : ");
                  14              ch=sc.nextInt();                             //Accepting choice

                  15              System.out.println(" *********** ");
                  16              switch(ch)

                  17              {
                  18              case 1: sum = num1 + num2;                   //Calculation of sum

                  19              System.out.println("Sum of " + num1 + " and "+num2 +" is : "+sum);
                  20              break;

                  21              case 2: diff = num1 - num2;            //Calculation of difference
                  22              System.out.println("Difference of " + num1 + " and "+num2 +" is : "+diff);

                  23              break;
                  24              case 3: pro = num1 * num2;                   //Calculation of product

                  25              System.out.println("Product of " + num1 + " and "+num2 +" is : "+pro);
                  26              break;

                  27              case 4: quo = (double)num1 / (double)num2; //Calculation of quotient
                  28              System.out.println("Quotient of " + num1 + " and "+num2 +" is : "+quo);
                  29              break;

                  30              case 5: rem = num1 % num2;                   //Calculation of remainder

                  31              System.out.println("Remainder of " + num1 + " and "+num2 +" is : "+rem);
                  32              break;
                  33              default: System.out.println("Wrong Choice");

                  34              }                                            //close of switch case

                  35           }                                               //close of main()
                  36      }                                                    //close of class





                                                                                             Internal Assessment  285
   282   283   284   285   286   287   288   289   290   291   292