How to calculate the volume of a sphere in Kotlin

1 Answer

0 votes
import kotlin.math.PI
import kotlin.math.pow

fun sphereVolume(r: Double): Double {
    return 4.0 / 3.0 * PI * r.pow(3)
}

fun main() {
    val radius = 5.0

	println("Volume of sphere = ${sphereVolume(radius)}")
}




/*
run:
  
Volume of sphere = 523.5987755982989
  
*/

 



answered Nov 8, 2024 by avibootz

Related questions

1 answer 116 views
1 answer 102 views
1 answer 98 views
1 answer 107 views
1 answer 158 views
1 answer 150 views
...