File tree 1 file changed +19
-0
lines changed
src/main/java/com/thealgorithms/maths 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,25 @@ public static double surfaceAreaCube(final double sideLength) {
35
35
return 6 * sideLength * sideLength ;
36
36
}
37
37
38
+ /**
39
+ * Calculate the surface area of a pyramid with a square base.
40
+ *
41
+ * @param sideLength side length of the square base
42
+ * @param slantHeight slant height of the pyramid
43
+ * @return surface area of the given pyramid
44
+ */
45
+ public static double surfaceAreaPyramid (final double sideLength , final double slantHeight ) {
46
+ if (sideLength <= 0 ) {
47
+ throw new IllegalArgumentException ("Must be a positive sideLength" );
48
+ }
49
+ if (slantHeight <= 0 ) {
50
+ throw new IllegalArgumentException ("Must be a positive slantHeight" );
51
+ }
52
+ double baseArea = sideLength * sideLength ;
53
+ double lateralSurfaceArea = 2 * sideLength * slantHeight ;
54
+ return baseArea + lateralSurfaceArea ;
55
+ }
56
+
38
57
/**
39
58
* Calculate the surface area of a sphere.
40
59
*
You can’t perform that action at this time.
0 commit comments