File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,24 @@ public static double surfaceAreaCube(final double sideLength) {
3434 }
3535 return 6 * sideLength * sideLength ;
3636 }
37+ /**
38+ * Calculate the surface area of a pyramid with a square base.
39+ *
40+ * @param sideLength side length of the square base
41+ * @param slantHeight slant height of the pyramid
42+ * @return surface area of the given pyramid
43+ */
44+ public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
45+ if (sideLength <= 0 ) {
46+ throw new IllegalArgumentException ("Must be a positive sideLength" );
47+ }
48+ if (slantHeight <= 0 ) {
49+ throw new IllegalArgumentException ("Must be a positive slantHeight" );
50+ }
51+ double baseArea = sideLength * sideLength ;
52+ double lateralSurfaceArea = 2 * sideLength * slantHeight ;
53+ return baseArea + lateralSurfaceArea ;
54+ }
3755
3856 /**
3957 * Calculate the surface area of a sphere.
You can’t perform that action at this time.
0 commit comments