forked from ghostmkg/dsa-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAreaCalculator.java
More file actions
55 lines (46 loc) · 1.95 KB
/
AreaCalculator.java
File metadata and controls
55 lines (46 loc) · 1.95 KB
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
import java.util.Scanner;
public class AreaCalculator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int choice;
do {
System.out.println("\n--- Area Calculator ---");
System.out.println("1. Circle");
System.out.println("2. Rectangle");
System.out.println("3. Triangle");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();
switch (choice) {
case 1:
System.out.print("Enter radius of circle: ");
double radius = sc.nextDouble();
double circleArea = 3.14159 * radius * radius;
System.out.println("Area of Circle = " + circleArea);
break;
case 2:
System.out.print("Enter length of rectangle: ");
double length = sc.nextDouble();
System.out.print("Enter width of rectangle: ");
double width = sc.nextDouble();
double rectArea = length * width;
System.out.println("Area of Rectangle = " + rectArea);
break;
case 3:
System.out.print("Enter base of triangle: ");
double base = sc.nextDouble();
System.out.print("Enter height of triangle: ");
double height = sc.nextDouble();
double triArea = 0.5 * base * height;
System.out.println("Area of Triangle = " + triArea);
break;
case 4:
System.out.println("Exiting program. Goodbye!");
break;
default:
System.out.println("Invalid choice! Please try again.");
}
} while (choice != 4);
sc.close();
}
}