I'm trying to approoximate pi using the Leibniz series and the question I got is:
"You can approximate π by using the following series:
pi = 4(1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ((-1)^i+1)/2i - 1
Write a program that displays the π value for i = 10,000, 20,000, ..., to 100,000"
Now the question itself is fairly vague, and that's mainly what I want help with, so far I've gotten to here.
public class Q2 {
public static void main(String[] args)
{
for (int i = 1; i <= 10000; i++)
{
double pi = 4* (1 - (1/3) + (1/5) - (1/7) + (1/9) - (1/11) +
(Math.pow((-1),(i+1)) ) / ((2*i)-1));
if(i%10000==0)
{
System.out.println();
}
}
}
}
The problem is that when run the system produces no result, if ran with an extra else statement to check the vallue of pi it gives back variations on 4.000200030004501 and 3.999799949987497.
if(i%10000==0)
{
System.out.println();
}
else
{
System.out.print(pi);
}
Am I augmenting i incorrectly? I feel like theres an aspec to the question that's staring in my face and I'm missing it! Thanks, Dave.