File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 1- package com .thealgorithms .maths ;
1+ Dpackage com .thealgorithms .maths ;
22
33/**
44 * Find the area of various geometric shapes
@@ -193,3 +193,24 @@ public static double surfaceAreaCone(final double radius, final double height) {
193193 return Math .PI * radius * (radius + Math .pow (height * height + radius * radius , 0.5 ));
194194 }
195195}
196+
197+
198+ /**
199+ * Calculate the surface area of a pyramid with a square base.
200+ *
201+ * @param sideLength side length of the square base
202+ * @param slantHeight slant height of the pyramid
203+ * @return surface area of the given pyramid
204+ */
205+ public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
206+ if (sideLength <= 0 ) {
207+ throw new IllegalArgumentException ("Must be a positive sideLength" );
208+ }
209+ if (slantHeight <= 0 ) {
210+ throw new IllegalArgumentException ("Must be a positive slantHeight" );
211+ }
212+ double baseArea = sideLength * sideLength ;
213+ double lateralSurfaceArea = 2 * sideLength * slantHeight ;
214+ return baseArea + lateralSurfaceArea ;
215+ }
216+
You can’t perform that action at this time.
0 commit comments