Kotlin program to find surface area of a cuboid

Kotlin | Surface area of a cuboid: Here, we are implementing a Kotlin program to find surface area of a cuboid.
Submitted by IncludeHelp, on May 08, 2020

A cuboid is a three-dimensional figure which is bounded by 6 rectangular planes, they have different magnitude of length, width and height.

Formula to find surface area of a cuboid: 2( length*width + length*height + height*width)

Given length, width and height, we have to find surface area of a cuboid.

Example:

    Input:
    length = 3
    width  = 4
    height = 6

    Output:
    Surface Area of Cuboid is :108.0

Program to find surface area of a cuboid 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 Length of Cuboid
    print("Enter Cuboid Length : ")
    val length = scanner.nextDouble()

    //Input Width of Cuboid
    print("Enter Cuboid Width : ")
    val width = scanner.nextDouble()

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

    //Calculate surface area of cuboid
    val areaCuboid = 2*( length*width + length*height + height*width )

    //Print surface area of cuboid
    println("Surface Area of Cuboid is :$areaCuboid")
}

Output

Run 1:
Enter Cuboid Length : 3
Enter Cuboid Width : 4
Enter Cuboid Height : 6
Surface Area of Cuboid is :108.0
---
Run 2:
Enter Cuboid Length : 5
Enter Cuboid Width : 6
Enter Cuboid Height : 2
Surface Area of Cuboid is :104.0


Comments and Discussions!

Load comments ↻





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