Skip to content

Commit 809db9d

Browse files
committed
Added surface area calculation for pyramid
1 parent 873dd97 commit 809db9d

File tree

1 file changed

+18
-0
lines changed
  • src/main/java/com/thealgorithms/maths

1 file changed

+18
-0
lines changed

src/main/java/com/thealgorithms/maths/Area.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
package 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

0 commit comments

Comments
 (0)