Helping on Calculating Pie
Hi everyone, a helping hand will surely help. I am confused with my code. I am trying to solve the question below that solves for pie. When I run the program, the output is:
The value of pie to the 200,000th term is 4.000000
This is not the right answer and I can't figure out what I did wrong. Can someone please help? Thanks a lot.
Calculate the value of π from the infinite series
π = 4 - (4/3) + (4/5) - (4/7) + (4/9) - (4/11) + ....
Print a table that shows the value of π approximated by computing one term of this series, by two terms, by three terms, and so on.
public class CalculatingPie
public static void main( String args )
double initial = 4;
double infiniteSeries = 0;
for ( int counter = 0; counter <= 100000; counter += 4)
infiniteSeries = ( 4 / (5 + counter)) - (4 / (3 + counter ));
double pie = initial + infiniteSeries;
System.out.printf( "The value of pie to the 200,000th term is %f", pie);
} // end method main
} // end class CalculatingPie