mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 20:20:56 +08:00
Add surfaceAreaCylinder (hacktoberfest) (#2337)
This commit is contained in:
@ -28,6 +28,9 @@ public class Area {
|
|||||||
|
|
||||||
/* test circle */
|
/* test circle */
|
||||||
assert Double.compare(surfaceAreaCircle(20), 1256.6370614359173) == 0;
|
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) {
|
private static double surfaceAreaRectangle(double length, double width) {
|
||||||
return length * 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
|
* Calculate the area of a square
|
||||||
|
Reference in New Issue
Block a user