-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsWitch.java
66 lines (51 loc) · 1.58 KB
/
sWitch.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.Scanner;
public class sWitch
{
Scanner enter = new Scanner(System.in);
int l;
int w;
int r;
int h;
sWitch()
{
System.out.println("*********THIS CODE WILL HELP UNDERSTAND HOW SWITHC WORKS**********");
display();
}
public void display()
{
System.out.print("Do you want to calculate area: ");
Scanner sc = new Scanner(System.in);
String s = sc.next();
String s1 = "yes";
if(s.equals(s1))
{
System.out.print("For which you want to calculate area (Triangle,Square or Circle) : ");
Scanner input = new Scanner(System.in);
String in = input.next();
switch(in)
{
case "triangle" : System.out.print("Enter length of the triangle: ");
l = enter.nextInt();
System.out.print("Enter height of the triangle: ");
h = enter.nextInt();
System.out.print("Area of the triangle: "+(0.5*l*h));
break;
case "recatangle" : System.out.print("Enter length of the rectangle: ");
l = enter.nextInt();
System.out.print("Enter width of the rectangle: ");
w = enter.nextInt();
System.out.print("Area of the rectangle: "+(l*w));
break;
case "circle" : System.out.print("Enter radius of circle: ");
r = enter.nextInt();
System.out.print("Area of the circle: "+(3.14*r*r));
break;
default : System.out.println("Wrong choice !!!");
}
}
}
public static void main(String args[])
{
new sWitch();
}
}