-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay-02-Java-Q10
More file actions
61 lines (47 loc) · 1.63 KB
/
Copy pathDay-02-Java-Q10
File metadata and controls
61 lines (47 loc) · 1.63 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
/*Veena wants to learn shape calculation for Square,Rectangle,Circle,Triangle to implements in programming.Could you please help her to how to write the program. Notes: - Square formula:4a - Rectangle formula:2(l+w) - Circle formula:2πr - Triangle formula:side+base+side
Input Format
First input consist of integer for side.
Second and third input consists of integer for Length and Width.
forth input consist of radius.
Fifth,Sixth and Seventh input consist of Base1,side and Base2 .
Constraints
No Constraints
Output Format
Execute the area of shape calculation values.
Sample Input 0
9
8
7
6
5
4
3
Sample Output 0
Perimeter of Square:36
Perimeter of Rectangle:30
Perimeter of Circle:37.69
Perimeter of Triangle:12*/
#Answer
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int side = sc.nextInt();
int length = sc.nextInt();
int width = sc.nextInt();
int radius = sc.nextInt();
int base1 = sc.nextInt();
int triSide = sc.nextInt();
int base2 = sc.nextInt();
int periSquare = 4 * side;
int periRectangle = 2 * (length + width);
double periCircle = 2 * Math.PI * radius;
periCircle = ((int)(periCircle * 100)) / 100.0;
int periTriangle = base1 + triSide + base2;
System.out.println("Perimeter of Square:" + periSquare);
System.out.println("Perimeter of Rectangle:" + periRectangle);
System.out.printf("Perimeter of Circle:%.2f\n", periCircle);
System.out.println("Perimeter of Triangle:" + periTriangle);
sc.close();
}
}