Kotlin program to find area of Equilateral Triangle

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

Problem statement

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

Kotlin - Find Area of Equilateral Triangle

Formula to find area of Equilateral Triangle: area = ( 1.73 × side × side)/4

Example:

Input:
side = 7

Output:
area = 21.1925

Program to find area of Equilateral Triangle in Kotlin

package com.includehelp

import java.util.*
import kotlin.math.pow

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

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

    //Input Side of Equilateral Triangle
    print("Enter Side of Equilateral Triangle : ")
    val side = scanner.nextDouble()

    //Calculate Area of Equilateral Triangle
    val areaEquilateralTriangle = (1.73*side.pow(2))/4

    //Print Area
    println("Area of Equilateral Triangle on Side($side) is :$areaEquilateralTriangle")
}

Output

Run 1:
Enter Side of Equilateral Triangle : 7
Area of Equilateral Triangle on Side(7.0) is :21.1925
---
Run 2:
Enter Side of Equilateral Triangle : 21
Area of Equilateral Triangle on Side(21.0) is :190.7325

Comments and Discussions!

Load comments ↻





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