Kotlin program to find area of Square

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

Kotlin - Find area of Square

Formula to find area of Square: area = side*side

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

Example:

    Input:
    side = 6

    Output:
    area = 36.0

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

    //Calculate Area of square
    val squareArea = side*side;

    //Print Area
    println("Area of Square is : $squareArea")
}

Output

Run 1:
Enter Side of Square : 6
Area of Square is : 36.0
---
Run 2:
Enter Side of Square : 4.5
Area of Square is : 20.25

Comments and Discussions!

Load comments ↻





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