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 11package com .thealgorithms .maths ;
2+ /**
3+ * Calculate the surface area of a pyramid with a square base.
4+ *
5+ * @param sideLength side length of the square base
6+ * @param slantHeight slant height of the pyramid
7+ * @return surface area of the given pyramid
8+ */
9+ public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
10+ if (sideLength <= 0 ) {
11+ throw new IllegalArgumentException ("Must be a positive sideLength" );
12+ }
13+ if (slantHeight <= 0 ) {
14+ throw new IllegalArgumentException ("Must be a positive slantHeight" );
15+ }
16+ double baseArea = sideLength * sideLength ;
17+ double lateralSurfaceArea = 2 * sideLength * slantHeight ;
18+ return baseArea + lateralSurfaceArea ;
19+ }
220
321/**
422 * Find the area of various geometric shapes
You can’t perform that action at this time.
0 commit comments