Q:

Kotlin program to find area of circle

belongs to collection: Kotlin Basic Programs

0

Given radius of the circle, we have to find the area of circle.

Example:

    Input:
    Radius: 3

    Output:
    Area of circle: 28.259999999999998

To find the area of the circle, we use the formula: π r2.

Here,

  • π stands for PI which is a mathematical constant and it's value of 3.14, it defined as the ratio of a circle’s circumference to its diameter and it also has the various equivalent definitions.
  • r is the radius of the circle.

All Answers

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

Program to find area of circle in Kotlin

package com.includehelp.basic

import java.util.*

// PI Constant Value
val PI = 3.14

/* function to calculate area of circle of given radius */
fun getAreaOfCirlce(radius: Double): Double {
    return PI * radius * radius
}

// Main Method Entry Point of Program
fun main(args:Array<String>){
    val sc = Scanner(System.`in`)
    
    // Input Radius
    println("Enter Circle Radius  : ")
    val radius = sc.nextDouble()
    
    // Call function to get Area of Circle
    val areaOfCircle = getAreaOfCirlce(radius)
    
    // Print Area of Circle
    println("Area of Circle : $areaOfCircle") 
}

Output

Run 1:
Enter Circle Radius  :
3
Area of Circle : 28.259999999999998
-----
Run 2:
Enter Circle Radius  :
8
Area of Circle : 200.96

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 Rectangle... >>
<< Kotlin program to find sum of digits of a number...