File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -175,6 +175,26 @@ public static double surfaceAreaHemisphere(final double radius) {
175175 }
176176 return 3 * Math .PI * radius * radius ;
177177 }
178+
179+ /**
180+ * Calculate the surface area of a pyramid with a square base.
181+ *
182+ * @param sideLength side length of the square base
183+ * @param slantHeight slant height of the pyramid
184+ * @return surface area of the given pyramid
185+ */
186+ public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
187+ if (sideLength <= 0 ) {
188+ throw new IllegalArgumentException ("Must be a positive sideLength" );
189+ }
190+ if (slantHeight <= 0 ) {
191+ throw new IllegalArgumentException ("Must be a positive slantHeight" );
192+ }
193+ double baseArea = sideLength * sideLength ;
194+ double lateralSurfaceArea = 2 * sideLength * slantHeight ;
195+ return baseArea + lateralSurfaceArea ;
196+ }
197+
178198
179199 /**
180200 * Calculate the surface area of a cone.
You can’t perform that action at this time.
0 commit comments