Page 220 - ComputerScience_Class_11
P. 220

13              System.out.println("Enter your choice : ");
                14              ch=sc.next().charAt(0);

                15              switch(ch)
                16              {
                17                  case 'r' :
                18                  case 'R' :  System.out.println("Enter length and breadth");
                19                              l=sc.nextInt();
                20                              b=sc.nextInt();
                21                              arec=l*b;
                22                              System.out.println(" Area of a rectangle : "+(arec));

                23                              break;
                24                  case 'i' :
                25                  case 'I' :  System.out.println("Enter base and height");
                26                              s1=sc.nextInt();
                27                              s2=sc.nextInt();
                28                              aiso=s1*s2/2;

                                                 System.out.println("Area of an isosceles triangle :"+
                29                                  (aiso));
                30                              break;
                31                  case 'c' :
                32                  case 'C' :  System.out.println("Enter radius");
                33                              r=sc.nextDouble();
                34                              acir=3.142 * r * r;
                35                              System.out.println(" Area of a circle : "+(acir));
                36                              break;

                37                  default:    System.out.println("You have entered the wrong choice");
                38              }
                39          }
                40      }

              The output of the preceding program is as follows:

                     BlueJ: Terminal Window - Java

                 Options

                Choice r: Area of a rectangle
                Choice i: Area of an isosceles triangle
                Choice c: Area of a circle
                Enter your choice :
                i
                Enter base and height
                4
                3
                Area of an isosceles triangle : 6.0






                  218  Touchpad Computer Science (Ver. 3.0)-XI
   215   216   217   218   219   220   221   222   223   224   225