Hmmmmmm....I think I mighta found the problem.
You had some extra brackets that you didn't need.
public class Assign3_Roberts {
public static void main(String[] args)
{
for (int i = 100; i <= 1000; i += 100) {
double pi4 = 1.0;
for(int j = 2; j <= i; j += 2)
pi4 = pi4 - 1/(2*(double)j - 1) + 1/(2*(double)j + 1);
double pi = 4.0*pi4;
System.out.println("When i is " + i + " PI is " + pi);
}
//next section
//determine value of i
int i = 0;
double pi = 100;
do
{
i ++;
double pi4 = 1.0;
for(int j = 2; j <= i; j += 2)
pi4 = pi4 - 1/(2*(double)j - 1) + 1/(2*(double)j + 1);
pi = 4.0*pi4;
} while (pi > 3.1419);
System.out.println("value of i to give PI equal or smaller than 3.1419 is " + i);
}
}
----jGRASP: operation complete.
----jGRASP exec: java Assign3_Roberts
When i is 100 PI is 3.1514934010709914
When i is 200 PI is 3.1465677471829556
When i is 300 PI is 3.1449149035588526
When i is 400 PI is 3.144086415298761
When i is 500 PI is 3.143588659585789
When i is 600 PI is 3.143256545948974
When i is 700 PI is 3.1430191863875865
When i is 800 PI is 3.142841092554028
When i is 900 PI is 3.1427025311614294
When i is 1000 PI is 3.1425916543395442
value of i to give PI equal or smaller than 3.1419 is 3254