Math.Pi Java Code Example

Last Updated On Monday 30th May 2022

Code Example 1:

	public class MathPI {

  public static void main(String args[]) {

    double pi = Math.PI;
    System.out.println(pi);
    System.out.println(pi*2);
  }
}
	

The Above Code Outputs

	3.141592653589793
6.283185307179586
	

Code Example 2:

	public class MathPI {
  public static void main(String args[]) {
    final double PI = 3.1415;
    double r = 5;
    double CircleArea = PI * (r * r);
    double CircleCircumference = 2 * (PI * r);
    System.out.println("Area : " + CircleArea);
    System.out.println("Circumference : " + CircleCircumference);
  }
}
	

The Above Code Outputs

	Area : 78.53750000000001
Circumference : 31.415000000000003