File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
src/main/java/com/thealgorithms/maths Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,27 @@ public static double surfaceAreaCube(final double sideLength) {
3535 return 6 * sideLength * sideLength ;
3636 }
3737
38+ /**
39+ * Calculate the surface area of a cuboid.
40+ *
41+ * @param length length of the cuboid
42+ * @param width width of the cuboid
43+ * @param height height of the cuboid
44+ * @return surface area of given cuboid
45+ */
46+ public static double surfaceAreaCuboid (final double length , double width , double height ) {
47+ if (length <= 0 ) {
48+ throw new IllegalArgumentException ("Length must be greater than 0" );
49+ }
50+ if (width <= 0 ) {
51+ throw new IllegalArgumentException ("Width must be greater than 0" );
52+ }
53+ if (height <= 0 ) {
54+ throw new IllegalArgumentException ("Height must be greater than 0" );
55+ }
56+ return 2 * (length * width + length * height + width * height );
57+ }
58+
3859 /**
3960 * Calculate the surface area of a sphere.
4061 *
You can’t perform that action at this time.
0 commit comments