From d6250d29c5fffa9d0e66ed3c2737541b91324134 Mon Sep 17 00:00:00 2001 From: FruitiousPotato <197135458+FruitiousPotato@users.noreply.github.com> Date: Thu, 29 Oct 2026 15:46:50 -0400 Subject: [PATCH] Added surface area calculation for pyramid --- .../maths/SurfaceAreaOfPyramid.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/com/thealgorithms/maths/SurfaceAreaOfPyramid.java diff --git a/src/main/java/com/thealgorithms/maths/SurfaceAreaOfPyramid.java b/src/main/java/com/thealgorithms/maths/SurfaceAreaOfPyramid.java new file mode 100644 index 000000000000..386a8b314d8a --- /dev/null +++ b/src/main/java/com/thealgorithms/maths/SurfaceAreaOfPyramid.java @@ -0,0 +1,20 @@ +/** +* 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; +}public static