forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerimeter.java
More file actions
38 lines (37 loc) · 1.16 KB
/
Copy pathPerimeter.java
File metadata and controls
38 lines (37 loc) · 1.16 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
package com.thealgorithms.maths;
public class Perimeter {
public static void main(String[] args) {
System.out.println(perimeter_polygon(5,4));
System.out.println(perimeter_rectangle(3,4));
System.out.printf("%,3f",circumference(5));
}
// Perimeter of different 2D geometrical shapes
/**
*Calculate the Perimeter of polygon.
* @parameter length of side.
* @parameter number of sides.
* @return Perimeter of given polygon
*/
public static float perimeter_polygon( int n, float side){
float perimeter = n*side;
return perimeter;
}
/**
*Calculate the Perimeter of rectangle.
* @parameter length and breadth.
* @return Perimeter of given rectangle
*/
public static float perimeter_rectangle( float length, float breadth){
float perimeter = 2*(length + breadth);
return perimeter;
}
/**
*Calculate the circumference of circle.
* @parameter radius of circle.
* @return circumference of given circle.
*/
public static double circumference( float r){
double circumference = 2*Math.PI*r;
return circumference;
}
}