Value of PI in Java

PI value in mathematics is a very important value used in number of formulas. In java value of PI can be obtained through Math class of java.lang package.

Math.PI is a double constant whose value = 3.141592653589793

Let us look at a program to calculate area of circle using Math.PI

public class Tech4Humans {
public static void main(String[] args) {
		
		double piValue = Math.PI;
		System.out.println("Value of PI in java = "+piValue);
		
		double circleRadius = 2;
		double areaCircle = Math.PI * circleRadius * circleRadius;
		
		System.out.println("Area of circle = "+areaCircle);

	}
}

Output

Value of PI in java = 3.141592653589793
Area of circle = 12.566370614359172

Leave a Comment