Java Program to Find Area and Circumference of Circle

In the previous article we have discussed Java Program to Find Area and Perimeter of Square

In this article we will discuss about how to find area and circumference of circle.

Program to Find Area and Circumference of Circle

Before jumping into the program directly, let’s first know how can we get area and circumference of circle.

Formula for Area of Circle = PI*(r*r)

Formula for Circumference of Circle = 2*PI*r

Where,

  • 'PI' represents PI value i.e. 3.141
  • 'r' represents radius of circle.

 Example:

Example- To find Area of Circle

When radius of circle = 1
Then area of square => area = PI*(r*r)
                                 => area =  3.141592653589793
Example- To find Circumference  of Circle

When radius of circle = 1
Then circumference of circle => circumference  = 2*PI*r
                                              => circumference  = 6.283185307179586

Now, let’s see the program.

Don’t stop learning now. Get hold of all the important Java fundamentals with the Simple java program example guide and practice well.

Method-1: Java Program to Find Area and Circumference of Circle By Using Static Values

import java.util.*;

public class Main
{
   public static void main(String args[])
   {
       //radius value declared
      double r = 1;
      //Finding area of circle
      double area = Math.PI * (r * r);
      System.out.println("Area of circle : " + area);
      //Finding circumference of circle
      double circumference= Math.PI * 2*r;
      System.out.println( "Circumference of the circle : "+circumference) ;
   }
}
Output:

Area of circle : 3.141592653589793
Circumference of the circle : 6.283185307179586

Method: Java Program to Find Area and Circumference of Circle By Using User Input Values

import java.util.*;

public class Main
{
   public static void main(String args[])
   {
      Scanner sc = new Scanner(System.in);
      //Asking the user for radius input
      System.out.print("Enter the radius: ");
      double r = sc.nextDouble();
      //Finding area of circle
      double area = Math.PI * (r * r);
      System.out.println("Area of circle : " + area);
      //Finding circumference of circle
      double circumference= Math.PI * 2*r;
      System.out.println( "Circumference of the circle : "+circumference) ;
   }
}
Output:

Enter the radius: 2
Area of circle : 12.566370614359172
Circumference of the circle : 12.566370614359172

Method-3: Java Program to Find Area and Circumference of Circle By Using User Defined Method

import java.util.*;

public class Main
{
   public static void main(String args[])
   {
      Scanner sc = new Scanner(System.in);
      //Asking the user for radius input
      System.out.print("Enter the radius: ");
      double radius = sc.nextDouble();
      //calling the calculate() method
      calculate(radius);
   }
   
    //user defined method to find area and circumference
    public static void calculate(double r)
    {
      //Finding area of circle
      double area = Math.PI * (r * r);
      System.out.println("Area of circle : " + area);
      //Finding circumference of circle
      double circumference= Math.PI * 2*r;
      System.out.println( "Circumference of the circle : "+circumference) ;
   }
}
Output: 

Enter the radius: 2 
Area of circle : 12.566370614359172 
Circumference of the circle : 12.566370614359172

Have you mastered basic programming topics of java and looking forward to mastering advanced topics in a java programming language? Go with these ultimate Advanced java programs examples with output & achieve your goal in improving java coding skills.

Related Java Programs: