-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathAreas of Different Shapes
81 lines (74 loc) · 2.04 KB
/
Areas of Different Shapes
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.util.*;
class Area
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Hello, In this program you can find the different shape's area");
System.out.println("Select your choice");
System.out.println("1. Area of Square");
System.out.println("2. Area of Rectangle");
System.out.println("3. Area of Circle");
System.out.println("4. Area of Triangle");
System.out.println("5. Exit");
int choice = sc.nextInt();
switch(choice)
{
case 1:
areaSquare();
break;
case 2:
areaRectangle();
break;
case 3:
areaCircle();
break;
case 4:
areaTriangle();
break;
case 5:
exit();
break;
default:
System.out.println("Wrong choice");
}
}
static void areaSquare()
{
System.out.println("You have selected Area of Square\nEnter square side :");
Scanner c = new Scanner(System.in);
float x = c.nextFloat();
float result = x*x;
System.out.println("The are of square for given data is:"+ result+"sq.");
}
static void areaRectangle()
{
System.out.println("You have selected Area of Rectangle\nEnter length and breath :");
Scanner sc = new Scanner(System.in);
float x = sc.nextFloat();
float y = sc.nextFloat();
float result = x*y;
System.out.println("the area of rectangle is " + result+"sq.");
}
static void areaCircle()
{
System.out.println("You have selected Area of Circle"+"sq.");
float pi = 22/7;
Scanner sc = new Scanner(System.in);
System.out.println("Enter radius of circle");
float x = sc.nextFloat();
float result = pi*(x * x);
System.out.println("The area of circle for given data is:"+ result+"sq.");
}
static void areaTriangle()
{ Scanner sc = new Scanner(System.in);
System.out.println("You have selected Area of Triangle\nEnter height and base of triangle :");
float x =sc.nextFloat();
float y = sc.nextFloat();
float result = 1/2*(x*y);
System.out.println("The area of triangle is "+ result+"sq.");
}
static void exit()
{
System.out.println("Good bye user");
}
}