Write Java program to Calculate Perimeter of a Circle


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

  • The program first declares a double variable r 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 perimeter of the circle, the program uses the formula perimeter = 2 * PI * radius, where PI is the mathematical constant π (approximately equal to 3.14).
  • The program calculates the perimeter by multiplying the radius by 2, multiplying the result by π, and storing the final result in a double variable named per.
  • Finally, the program outputs the calculated perimeter to the console using the print() method, preceded by a string indicating that the value being printed is the perimeter of the circle.

Source Code

import java.util.Scanner;
public class Perimeter_Circle
{
	public static void main(String[] args)
	{
		double r;
		Scanner input = new Scanner(System.in);
		System.out.print("Enter the Radius of Circle : ");
		r = input.nextDouble();		
		double per = 2 * 3.14 * r;// circle parameter = 2PIr
		System.out.print("Perimeter of Circle : " + per);
	}
}

Output

Enter the Radius of Circle : 45
Perimeter of Circle : 282.6