Java program to find circumference of a circle

Let’s learn java program to find circumference of a circle.

Java program to find circumference of a circle

To calculate circumference of circle in java, first we have to get radius of circle from user using nextInt() method of Scanner class.

java program to find circumference of a circle

This user entered number is stored in integer variable “radius”. Then find circumference of a circle using below formula.

Also read – java program to find area of circle and rectangle

To find circumference of a circle formula is,

circumference = 2πr

Circumference of circle is twice the product of radius and value of PI. This product is stored in double variable “circumference”.

Also read – java program to find area of circle and rectangle using interface

Lastly circumference is printed on console. Here’s the java program to calculate circumference of circle.

import java.util.Scanner;
public class CircumferenceOfCircleJava
{
   public static void main(String[] args) 
   {
      int radius;
      double circumference;
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter the radius : ");
      radius = sc.nextInt();
      // double radius
      circumference = Math.PI * 2 * radius;
      System.out.println("Circumference of circle : " + circumference);
      sc.close();
   }
}


Output:

Please enter the radius : 10
Circumference of circle : 62.83185307179586


Also read – java program to find area of rectangle

Also read – java program to find area of circle

Also read – java program to find area of circle using class and object


java program to find perimeter of a circle

Here’s java program to find perimeter of a circle.

import java.util.Scanner;
public class PerimeterOfCircle
{
   public static void main(String[] args)
   {
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter the radius of the circle: ");
      double radius = sc.nextDouble();
      System.out.println("Perimeter of a circle: " + (2 * radius * Math.PI));
      sc.close();
   }
}


Output:

Please enter the radius of the circle: 5
Perimeter of a circle: 31.41592653589793


Also read – java program to calculate area of circle, rectangle and triangle using switch statement

Also read – java program to find area of circle using bufferedreader

Also read – write a program to calculate circle area using radius in java