-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerimeter.java
More file actions
91 lines (75 loc) · 3.51 KB
/
Copy pathPerimeter.java
File metadata and controls
91 lines (75 loc) · 3.51 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
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
82
83
84
85
86
87
88
89
90
91
// Perimeter Of Circle, Equilateral Triangle, Parallelogram, Rectangle, Square, Rhombus
import java.util.Scanner;
public class Perimeter {
public static void main(String[] args) {
// Scanner object to take input from standard input stream
Scanner scanner = new Scanner(System.in);
// Taking input
System.out.println("Enter choice for finding perimeter:");
System.out.println("1-Circle; 2-Equilateral Triangle; 3-Parallelogram; 4-Rectangle; 5-Square; 6-Rhombus");
int choice = scanner.nextInt();
// Variable to store perimeter
float perimeter;
if (choice == 1) {
// Taking input
System.out.println("Enter radius of circle:");
float radius = scanner.nextFloat();
// Logic for perimeter of circle
// Perimeter of circle = 2 * pi * radius
perimeter = (float) (2 * Math.PI * radius);
// Printing result
System.out.println("Perimeter of circle is: " + perimeter + " sq.unit");
} else if(choice == 2) {
// Taking input
System.out.println("Enter length of triangle:");
float side = scanner.nextFloat();
// Logic for perimeter of equilateral triangle
// Perimeter of equilateral triangle = 3 * side
perimeter = 3 * side;
// Printing result
System.out.println("Perimeter of equilateral triangle is: " + perimeter + " sq.unit");
} else if(choice == 3) {
// Taking input
System.out.println("Enter length of first parallel side:");
float length1 = scanner.nextFloat();
System.out.println("Enter length of second parallel side:");
float length2 = scanner.nextFloat();
// Logic for perimeter of parallelogram
// Perimeter of parallelogram = 2 * (sum of length of parallel sides)
perimeter = 2 * (length1 + length2);
// Printing result
System.out.println("Perimeter of parallelogram is: " + perimeter + " sq.unit");
} else if (choice == 4) {
// Taking input
System.out.println("Enter length of rectangle:");
float length = scanner.nextFloat();
System.out.println("Enter breadth of rectangle:");
float breadth = scanner.nextFloat();
// Logic for perimeter of rectangle
// Perimeter of rectangle = 2 * (length + breadth)
perimeter = 2 * (length + breadth);
// Printing result
System.out.println("Perimeter of rectangle is: " + perimeter + " sq.unit");
} else if (choice == 5) {
// Taking input
System.out.println("Enter length of side:");
float side = scanner.nextFloat();
// Logic for perimeter of square
// Perimeter of square = 4 * side
perimeter = 4 * side;
// Printing result
System.out.println("Perimeter of square is: " + perimeter + " sq.unit");
} else if (choice == 6) {
// Taking input
System.out.println("Enter length of side:");
float side = scanner.nextFloat();
// Logic for perimeter of rhombus
// Perimeter of rhombus = 4 * side
perimeter = 4 * side;
// Printing result
System.out.println("Perimeter of rhombus is: " + perimeter + " sq.unit");
} else {
System.out.println("Enter valid choice! Try Again.");
}
}
}