public class GregoryFormular {
public static void main(String [] args) {
double pi, temp;
long n, sign;
pi = 0.0;
temp = 1.0;
n = 1;
sign = 1;
while (Math.abs(temp) >= 1e-6) {
pi = pi + temp;
n = n + 2;
sign = -sign;
temp = (double) sign / (double) n;
}
pi = pi * 4;
System.out.println(pi);
}
}
GregoryFormular
最新推荐文章于 2024-08-18 23:25:39 发布