package cn.edu.bjut.chapter2; public class FractionSummation { public static void main(String[] args) { double sum = 0; for (int n = 1; (1.0 / n >= 1e-5); n++) { if (n % 2 == 0) { // 偶数 sum -= 1.0 / n; } else { // 奇数 sum += 1.0 / n; } } System.out.println(sum); } }