File tree Expand file tree Collapse file tree
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,17 +76,7 @@ public static double surfaceAreaSphere(final double radius) {
7676 * @param slantHeight slant height of the pyramid
7777 * @return surface area of the given pyramid
7878 */
79- public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
80- if (sideLength <= 0 ) {
81- throw new IllegalArgumentException ("" );
82- }
83- if (slantHeight <= 0 ) {
84- throw new IllegalArgumentException ("slant height must be greater than 0" );
85- }
86- double baseArea = sideLength * sideLength ;
87- double lateralSurfaceArea = 2 * sideLength * slantHeight ;
88- return baseArea + lateralSurfaceArea ;
89- }
79+
9080
9181 /**
9282 * Calculate the area of a rectangle.
@@ -232,4 +222,15 @@ public static double surfaceAreaCone(final double radius, final double height) {
232222 }
233223 return Math .PI * radius * (radius + Math .pow (height * height + radius * radius , 0.5 ));
234224 }
235- }
225+ public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
226+ if (sideLength <= 0 ) {
227+ throw new IllegalArgumentException ("Must be a positive sideLength" );
228+ }
229+ if (slantHeight <= 0 ) {
230+ throw new IllegalArgumentException ("Must be a positive slantHeight" );
231+ }
232+ double baseArea = sideLength * sideLength ;
233+ double lateralSurfaceArea = 2 * sideLength * slantHeight ;
234+ return baseArea + lateralSurfaceArea ;
235+
236+ }
You can’t perform that action at this time.
0 commit comments