Home »
Kotlin »
Kotlin Programs »
Kotlin Basic Programs
Kotlin program to find area of Rectangle
Kotlin | Area of Rectangle: Here, we are going to implement a Kotlin program to find the area of Rectangle.
Submitted by IncludeHelp, on May 22, 2020
Kotlin - Find area of Rectangle
Formula to find area of Rectangle: area = length*width
Given the value of length and width, we have to find the area of Rectangle.
Example
Input:
length = 2.6
width = 3.2
Output:
area = 8.32
Program to find area of Rectangle 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 Rectangle
print("Enter Rectangle Length : ")
val length = scanner.nextDouble()
//Input Width of Rectangle
print("Enter Rectangle Width : ")
val width = scanner.nextDouble()
//Calculate Area of Rectangle
val rectangleArea = length * width
//Print Area
println("Area of Rectangle is :$rectangleArea")
}
Output
Run 1:
Enter Rectangle Length : 2.6
Enter Rectangle Width : 3.2
Area of Rectangle is :8.32
---
Run 2:
Enter Rectangle Length : 6
Enter Rectangle Width : 8
Area of Rectangle is :48.0