Java Program to find out the area of circle


December 28, 2022, Learn eTutorial
1602

How to calculate the area of a circle?

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

find area of a circle with given radius

How to calculate the circle area using the Java program?

To calculate a circle's area in Java, 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 it as a = 3.14 * r * r. Then display it  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 the result.

 

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