Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Program to find perimeter of a circle in Kotlin

In this article, we will learn simple Kotlin program to find the Perimeter of a circle.

Program:
fun main(args: Array)
{
    print("Enter circle radius : ")
    val input = readLine()!!
    val radius: Double
    if(input.toIntOrNull() != null)
    {
        radius = input.toDouble()
        val pi: Double=3.14159
        val perimeter: Double = 2 * pi * radius
        print("Perimeter of Circle is : $perimeter")
    }
    else
    {
        print("Please enter valid input.")
    }
}
Output:
Enter circle Radius : 10
Perimeter of Circle is : 62.8318
Program to find the perimeter of a circle in Kotlin - Output

Description:
In the above program, we will take Input from a user to know the radius of a circle. To do so we have used readLine() function. Next, we have checked that input accepted from the user is valid integer or decimal number. If an input is not valid then it will print the message to enter valid input.

If the input is a valid integer or decimal number, we will store it to a variable named val perimeter. Next, we have taken variable pi to hold the value of mathematical constant π, which is 3.14159. To find the perimeter of a circle we have used an equation 2 * pi * radius, which is equivalent to 2πr.



This post first appeared on Ask For Program, please read the originial post: here

Share the post

Program to find perimeter of a circle in Kotlin

×

Subscribe to Ask For Program

Get updates delivered right to your inbox!

Thank you for your subscription

×