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

  • Given a radius of circle, find the area and circumference of a circle.

Area of circle:

  • Area of circle = PI * radius * radius.
    • e.g if radius is 5, then area of circle is
      • Area = 3.14 * 5 * 5
      • Area = 78.54

Circumference of circle

  • Circumference of circle is 2 * PI * radius
    • e.g if radius is 5, then circumference of circle is
      • Circumference = 2 * 3.14 * 5
      • Circumference = 31.42
area circumference 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
Scroll to Top