mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 12:11:28 +08:00
Add surfaceAreaCylinder (hacktoberfest) (#2337)
This commit is contained in:
@ -28,6 +28,9 @@ public class Area {
|
||||
|
||||
/* test circle */
|
||||
assert Double.compare(surfaceAreaCircle(20), 1256.6370614359173) == 0;
|
||||
|
||||
/* test cylinder */
|
||||
assert Double.compare(surfaceAreaCylinder(1,2), 18.84955592153876) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,6 +63,16 @@ public class Area {
|
||||
private static double surfaceAreaRectangle(double length, double width) {
|
||||
return length * width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate surface of a cylinder
|
||||
*
|
||||
* @param radius radius of the floor
|
||||
* @param height height of the cylinder.
|
||||
*/
|
||||
private static double surfaceAreaCylinder(double radius, double height) {
|
||||
return 2 * (Math.PI * radius * radius + Math.PI * radius * height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the area of a square
|
||||
|
Reference in New Issue
Block a user