Discuss / Java / 打卡

打卡

Topic source

YG嘿嘿

#1 Created at ... [Delete] [Delete and Lock User]
//注意类型转化问题
private static void test5() {
    double pi = 0;
    for (int i = 1; i < 100000001; i++) {
        if (i % 2 == 0) {
            pi -= (1.0 / ((2 * i) - 1));
        } else {
            pi += (1.0 / ((2 * i) - 1));
        }
    }
    System.out.println(pi * 4);
}

  • 1

Reply