参考代码:
public class Main1134 {
public static void main(String[] args) {
double PI = 1;
double i = 1;
int a = 0;
while (1 / (Math.abs(i) + 2) >= 1e-6) {
if (a == 0) {
i = (i + 2) * -1;
PI = PI + 1 / i;
a = 1;
continue;
}
if (a == 1) {
i = (i - 2) * -1;
PI = PI + 1 / i;
a = 0;
continue;
}
}
System.out.println(String.format("%.6f", 4 * PI));
}
}
0.0分
0 人评分