Kotlin program to find area of a cylinder

Kotlin | Area of a cylinder: Here, we are going to implement a Kotlin program to find area of a cylinder. Submitted by IncludeHelp, on May 08, 2020

Problem statement

Give radius and height, we have to find area of a cylinder.

Kotlin - Find area of a cylinder

A cylinder is a three-dimensional structure which has circular bases parallel to each other.

Formula to find area of a cylinder: 2*PI*(radius+height)

Example:

Input:
Radius = 5
Height = 7

Output:
Surface Area of Cylinder is :75.39822368615503

Program to find area of a cylinder in Kotlin

package com.includehelp

import java.util.*

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

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

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

    //Input Height
    print("Enter Height of Cylinder : ")
    val height = scanner.nextDouble()

    //Cylinder Surface Area
    val areaCylinder = 2*Math.PI*(radius+height)

    //Print Area
    println("Surface Area of Cylinder is :$areaCylinder")
}

Output

Run 1:
Enter Radius of Cylinder : 5
Enter Height of Cylinder : 7
Surface Area of Cylinder is :75.39822368615503
---
Run 2:
Enter Radius of Cylinder : 29
Enter Height of Cylinder : 4
Surface Area of Cylinder is :207.34511513692635

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.