Q:

Kotlin program to find volume of Sphere

belongs to collection: Kotlin Basic Programs

0

Formula to find volume of Sphere: volume =(4/3)*PI*r^3

Given the value of radius, we have to find the volume of Sphere.

Example:

    Input:
    radius = 7

    Output:
    volume = 1436.7550402417319

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to find volume of Sphere in Kotlin

package com.includehelp

import java.util.*
import kotlin.math.pow

//Main Function , Entry point of Program
fun main(args: Array<String>) {

    //Input Stream
    val scanner = Scanner(System.`in`)

    //Input Radius
    print("Enter Radius of Sphere : ")
    val radius = scanner.nextDouble()

    //Sphere Volume
    val sphereVolume = (4.0/3.0)*Math.PI*radius.pow(3)

    //Print Volume
    println("Sphere Volume on radius $radius is : $sphereVolume")
}

Output

Run 1:
Enter Radius of Sphere : 7
Sphere Volume on radius 7.0 is : 1436.7550402417319
---
Run 2:
Enter Radius of Sphere : 21
Sphere Volume on radius 21.0 is : 38792.38608652676

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Kotlin Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Kotlin program to reverse a number... >>
<< Kotlin program to find surface area of Sphere...