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 66public final class Area {
77 private Area () {
88 }
9+ /**
10+ * Calculate the surface area of a pyramid with a square base.
11+ *
12+ * @param sideLength side length of the square base
13+ * @param slantHeight slant height of the pyramid
14+ * @return surface area of the given pyramid
15+ */
16+ public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
17+ if (sideLength <= 0 ) {
18+ throw new IllegalArgumentException ("Must be a positive sideLength" );
19+ }
20+ if (slantHeight <= 0 ) {
21+ throw new IllegalArgumentException ("Must be a positive slantHeight" );
22+ }
23+ double baseArea = sideLength * sideLength ;
24+ double lateralSurfaceArea = 2 * sideLength * slantHeight ;
25+ return baseArea + lateralSurfaceArea ;
26+ }
927
1028 /**
1129 * String of IllegalArgumentException for radius
You can’t perform that action at this time.
0 commit comments