Page 172 - computer science (868) class 11
P. 172
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 side 1 and side 2");
26 s1=sc.nextInt();
27 s2=sc.nextInt();
28 aiso=1.0/4.0*s1*Math.sqrt(4*s2*s2 - s1*s1);
29 System.out.println(" Area of an isosceles triangle :
"+(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:
Choice r: Area of a rectangle
Choice i: Area of an isosceles triangle
Choice c: Area of a circle
Enter your choice:
i
Enter side 1 and side 2
4
170170 Touchpad Computer Science-XI

