How to calculate the surface area of cuboid in Scala

1 Answer

0 votes
object SurfaceAreaCuboidApp {

  // Pure function to compute the surface area of a cuboid
  def surfaceAreaCuboid(length: Double, width: Double, height: Double): Double =
    2 * (length * width + width * height + height * length)

  def main(args: Array[String]): Unit = {
    val length = 6.0
    val width  = 3.0
    val height = 4.0

    val surfaceArea = surfaceAreaCuboid(length, width, height)

    println(s"Surface Area of Cuboid is = $surfaceArea")
  }
}




/*
run:

Surface Area of Cuboid is = 108.0

*/

 



answered Mar 3 by avibootz
...