From 71c5a4cfd22fc3e6bdcd683400e36671eaf0b8bf Mon Sep 17 00:00:00 2001 From: KuroTg <122903517+KuroTg@users.noreply.github.com> Date: Fri, 30 Oct 2026 13:34:42 -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 84fc67159379..cc35f3009586 100644 --- a/src/main/java/com/thealgorithms/maths/Area.java +++ b/src/main/java/com/thealgorithms/maths/Area.java @@ -202,6 +202,24 @@ public static double surfaceAreaCircle(final double radius) { } return Math.PI * radius * radius; } +/** +* 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 hemisphere.