Java Tutorial Java Advanced Java References

Java Math - PI Field



The Java PI field is used to return the value of 𝜋 to the available precision. It returns the value of 𝜋 as 3.141592653589793.

Syntax

public const double PI = 3.141592653589793;

Parameters

No parameter is required.

Return Value

Returns the value of 𝜋 to the available precision.

Example:

In the example below, Math.PI constant is used to return the value of 𝜋 to the available precision.

public class MyClass {
  public static void main(String[] args) {
    double const_pi = Math.PI;
    System.out.println("Math.PI = " + const_pi);   
    System.out.println(
       "Area of the circle with radius 1.0 is: " + const_pi*1*1);
  }
}

The output of the above code will be:

Math.PI = 3.141592653589793
Area of the circle with radius 1.0 is: 3.141592653589793

❮ Java Math Methods