Write Java program to Calculate Area of a Circle


This is a Java program that calculates the area of a circle given its radius.

  • The program first declares a double variable rad to store the radius of the circle.
  • It then prompts the user to enter the radius of the circle using the nextDouble() method of the Scanner class.
  • To calculate the area of the circle, the program uses the formula area = PI * radius^2, where PI is the mathematical constant π (approximately equal to 3.14).
  • The program calculates the area by squaring the radius, multiplying the result by π, and storing the final result in a double variable named area.
  • Finally, the program outputs the calculated area to the console using the print() method, preceded by a string indicating that the value being printed is the area of the circle.

Source Code

import java.util.Scanner;
public class Circle_Area
{
	public static void main(String[] args)
	{
		double rad;
		Scanner input = new Scanner(System.in);
		System.out.print("Enter the Radius of Circle : ");
		rad = input.nextDouble();		
		double area = 3.14 * rad * rad; // circle area = PIr2
		System.out.print("Area of Circle : " + area);
	}
}

Output

Enter the Radius of Circle : 21
Area of Circle : 1384.74