From d87cdb0ec4950a1767f6c89fc858c8c709031004 Mon Sep 17 00:00:00 2001 From: SohumDesh Date: Fri, 30 Oct 2026 12:46:05 -0400 Subject: [PATCH] Added surface area calculatin for pyramid --- .../java/com/thealgorithms/maths/Area.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 84fc67159379..6b5fc7081933 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -35,6 +35,26 @@ public static double surfaceAreaCube(final double sideLength) { return 6 * sideLength * sideLength; } + + /** + * Calculate the surface area of a pyramid with a square base. + * + * @param sideLength side length of the square base + * @param slantHeight slant height of the pyramid + * @return surface area of the given pyramid + */ + public static double surfaceAreaPyramid(final double sideLength, final double slantHeight) { + if (sideLength <= 0) { + throw new IllegalArgumentException("Must be a positive sideLength"); + } + if (slantHeight <= 0) { + throw new IllegalArgumentException("Must be a positive slantHeight"); + } + double baseArea = sideLength * sideLength; + double lateralSurfaceArea = 2 * sideLength * slantHeight; + return baseArea + lateralSurfaceArea; + } + /** * Calculate the surface area of a cuboid. *