我有一个类似的代码.将就着用把
大概意思是一样的只是没有异常处理
public class a2and5
{
public static void main(String [] agrs)
{
int count=0;
double pi=0.0,l=1.0,diff,pi1;
diff=1;
while(Math.abs(diff)>0.01)
{
pi1=pi;
pi+=((4.0/(count*2.0+1.0))*l);
l*=-1.0;
System.out.print(pi+" "+count+"n");
count++;
diff=pi1-pi;
}
}
}
/*
3.1467739659661436 192
3.136438048653482 193
3.1467208250030967 194
3.1364906459749635 195
3.1466687630233094 196
3.1365421807448284 197
3.146617747495458 198
3.136592684838816 199
3.1465677471829556 200 */