Calculate Area / Circumference Of Circle Using Java Math.PI

In this example, we are going to explain the usage of Java Math.PI to calculate area / circumference of circle

On below example, we are using Math.PI for finding the area / circumference of circle.


Formula to find the Area/Circumference are below

Area = radius*radius*PI
Circumference = PI*radius*2

Calculate Area / Circumference Of Circle Using Java Math.PI

package com.examples;

//Java Program to calculate the area and circumference of circle

public class MathPIExample {
   
public static void main(String args[]) {
       
int radius = 50;
       
// Area = radius*radius*PI
       
double area = (radius * radius) * Math.PI;
        System.out.println
("Area of circle is " + area);
       
// Circumference = PI*radius*2
       
double circumference = radius * Math.PI * 2;
        System.out.println
("The circumference of the circle is " + circumference);
   
}
}
Output
Area of circle is 7853.981633974483
The circumference of the circle is 314.1592653589793





Your email address will not be published. Required fields are marked *