Site icon

Given radius, find area & circumference of circle in java (example)

Area of circle:

Circumference of circle

Fig 1: Area & Circumference of circle

Program : find area & circumference of circle in java

package org.learn;

import java.util.Scanner;

public class AreaAndCircuferenceOfCircle {

	public static void main(String[] args) {
		
		try (Scanner scanner = new Scanner(System.in)) {
			
			System.out.printf("1. Enter radius of circle : ");
			double radius = scanner.nextDouble();

			// Area of circle is PI * radius * radius
			double area = Math.PI * radius * radius;

			// Print area up to two precision
			System.out.printf("2. Area of circle is : %4.2f", area);

			// Circumference of circle is 2 * PI * radius
			double circumference = 2 * Math.PI * radius;

			// Print area up to two precision
			System.out.printf("\n3. Circumference of circle is : %4.2f", circumference);
		}
	}
}

Output: Area & circumference of circle in java

1. Enter radius of circle : 5
2. Area of circle is : 78.54
3. Circumference of circle is : 31.42

1. Enter radius of circle : 10
2. Area of circle is : 314.16
3. Circumference of circle is : 62.83
Exit mobile version