Dremendo Tag Line

Calculate area of a circle in Java

Input - Question 13

In this question, we will see how to input the radius of a circle in Java programming using the java input and find its area. To know more about java input click on the java input lesson.

Q13) Write a program in Java to input the radius of a circle and find its area. Area of a circle is πr2. Where r is the radius and the value of π (pie) is 22/7 or 3.142

Formula: area = 3.142 * r * r

Program

import java.util.Scanner;

public class Q13
{
    public static void main(String args[])
    {
        float r,a;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter radius of a circle ");
        r=sc.nextFloat();
        a=3.142f*r*r;
        System.out.println("Area=" + a);
    }
}

Output

Enter radius of a circle 5
Area=78.55
video-poster