Kotlin program to find area of a cube

Kotlin | Area of a Cube: Here, we are going to implement a Kotlin program to find the area of a cube where side value is given. Submitted by IncludeHelp, on May 08, 2020

A cube has 6 square faces, if edges length is side. Then the area of each square is side2, thus, the area of cube will be 6*sise2.

Kotlin - Find area of a cube

Given the value of side of the cube, we have to find its area.

Example:

Input:
side = 5

Output:
Area of cube = 150.0

Program to find area of a cube 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 side
    print("Enter Side of Cube : ")
    val side = scanner.nextDouble()

    //Cube Surface Area
    val areaCube = 6*Math.pow(side, 2.toDouble())

    //Print Area
    println("Cube Surface Area on Side ($side) is :$areaCube")
}

Output

Run 1:
Enter Side of Cube : 5
Cube Surface Area on Side (5.0) is :150.0
---
Run 2:
Enter Side of Cube : 12
Cube Surface Area on Side (12.0) is :864.0

Comments and Discussions!

Load comments ↻





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