Search code examples
javamethodspi

i am trying to get a method that estimates pi in java


Although the book that I am using to learn... says on the side note that it as a video note for this problem since I only have the e-book I can access it to know what am I doing wrong....

If anyone can help it would be appreciated.

Note that I am using m(i) = 4*(1 -1/3+1/5-1/7+....) and so on

public class PiEstimationWithMethod{

    public static void main(String[] args) {


    }
    public static double PiEstimation (double i){

        double Pi =4*(Math.pow(-1, i+1)/(2*i-1));

        Pi += (Pi);

        return Pi;

Solution

  • Directly using of java.lang.Math.PI is not interesting! :-) I suppose you are going to calculate parted sum of series such as, but forgot about cycle iteration.

    int limit=100;
    double v=0 
    for(int i=0;i<limit;i++){
      v+=(1-2*i%2)/(2*i+1);
    }
    v*=4;