File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,25 @@ public static double surfaceAreaSphere(final double radius) {
4848 return 4 * Math .PI * radius * radius ;
4949 }
5050
51+ /**
52+ * Calculate the surface area of a pyramid with a square base.
53+ *
54+ * @param sideLength side length of the square base
55+ * @param slantHeight slant height of the pyramid
56+ * @return surface area of the given pyramid
57+ */
58+ public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
59+ if (sideLength <= 0 ) {
60+ throw new IllegalArgumentException ("Must be a positive sideLength" );
61+ }
62+ if (slantHeight <= 0 ) {
63+ throw new IllegalArgumentException ("Must be a positive slantHeight" );
64+ }
65+ double baseArea = sideLength * sideLength ;
66+ double lateralSurfaceArea = 2 * sideLength * slantHeight ;
67+ return baseArea + lateralSurfaceArea ;
68+ }
69+
5170 /**
5271 * Calculate the area of a rectangle.
5372 *
You can’t perform that action at this time.
0 commit comments