Java Program to find out the area of circle

Here we are explaining how to calculate the area of a circle.

How to calculate the area of a circle?

The area or perimeter of the circle can be calculated by using the formula A=3.14 * r* r. Where r is the radius of the circle.

How to implement the java program to find out the area of a circle?

First, we have to declare the class Area. Create an object of the scanner class as sc and read the radius of the circle from the user into the variable r by using nextDouble() method. Calculate the area as a=3.14*r*r.Display area as a by using system.out.println() .

ALGORITHM

STEP 1: Declare the class Area with a public modifier.

STEP 2: Open the main() to start the program, Java program execution starts with the main()

STEP 3: Declare the variables a,r  as double and set pi=3.14.

STEP 4: Read the radius of the circle from the user into the variable r.

STEP 5: Calculate area as a=pi*r*r.

STEP 6: Display area as a.

 

Java Source Code

                                          import java.util.Scanner;
public class Area{
    public static void main(String[] args) {
        
        double pi = 3.14, a,r;
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the radius of the circle:");
        r = sc.nextDouble();
        a= pi * r * r;
        System.out.println("The Area of the circle is :"+a);
    }  
}
                                      

OUTPUT

Enter the radius of the circle:15
The Area of the circle is :706.5