Math PI value example in java

The code snippet below shows you how to obtain the PI value in Java. We can use the Math.PI static field to get the value of PI.

Below is the example code which is using the Math.PI.

package com.java.connect.math;
 
//Math PI value example in java
public class MathPIExample {
    public static void main(String[] args) {
 
        // The math's pi value represented by Math.PI
        System.out.println("PI value is : " + Math.PI);
 
        // Using the Math.PI to calculate area of a circle.
        double radius = 19;
        double area = Math.PI * Math.pow(radius, 2);
        System.out.println("The Circle Area is : " + area);
    }
}

The output of the above example will be as:

PI value is : 3.141592653589793
The Circle Area is : 1134.1149479459152