Kotlin program to find area of Triangle

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

Kotlin - Find area of Triangle

Formula to find area of Triangle: (width*height)/2

Given the value of width and height, we have to find the area of Triangle.

Example:

Input:
width = 6
height = 3

Output:
area = 9.0

Program to find area of Triangle 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 Base Width
    print("Enter Base Width of Triangle : ")
    val width = scanner.nextDouble()

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

    //Calculate Area of triangle
    val triangleArea = (width*height)/2

    //Print Area
    println("Area of Triangle is : $triangleArea")
}

Output

Run 1:
Enter Base Width of Triangle : 6
Enter Height of Triangle : 3
Area of Triangle is : 9.0

---
Run 2:
Enter Base Width of Triangle : 5
Enter Height of Triangle : 6.3
Area of Triangle is : 15.75

Comments and Discussions!

Load comments ↻





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