From 6f5f04f7d2293bfab7e73cc914dcd7112199d3bd Mon Sep 17 00:00:00 2001 From: ProfN1g45te1n <91499973+ProfN1g45te1n@users.noreply.github.com> Date: Mon, 20 Oct 2025 10:02:25 -0400 Subject: [PATCH] Added Surface Area Calculation for pyramid --- .../java/com/thealgorithms/maths/Area.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/com/thealgorithms/maths/Area.java b/src/main/java/com/thealgorithms/maths/Area.java index 7a06fd5e5fa0..a1202bc93544 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -193,3 +193,21 @@ public static double surfaceAreaCone(final double radius, final double height) { return Math.PI * radius * (radius + Math.pow(height * height + radius * radius, 0.5)); } } +/** +* 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; +}