Q:

Kotlin program to find area of Triangle

belongs to collection: Kotlin Basic Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Kotlin Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Kotlin program to find area of a cube... >>
<< Kotlin program to find area of Square...