/*
Calculate the volume of a cube in Kotlin.
---------------------------------------------------
A cube has equal side lengths. If each side has length "side",
the volume is:
volume = side³
Kotlin uses the standard library function `pow()` for exponentiation
on floating‑point numbers, and the `*` operator for integers.
*/
import kotlin.math.pow
// A clean, reusable function to compute cube volume.
// Using Double makes the function flexible for fractional side lengths.
fun cubeVolume(side: Double): Double {
require(side >= 0) { "Side length must be non-negative" }
// Kotlin's pow() is idiomatic for exponentiation.
return side.pow(3)
}
fun main() {
val side = 12.0
println("Side length: $side")
println("Volume of cube: ${cubeVolume(side)}")
}
/*
run:
Side length: 12.0
Volume of cube: 1728.0
*/