1.关于1/1-1/2+1/3-1/4...+1/99-1/100的计算
public class TestDemo { public static void main(String[] args) { double n = 1; double temp = 0; double sum = 0; while (n <= 100){ temp += Math.pow((-1),(n+1))*(1/n); //Math.pow((-1),(n+1))(-1)的n+1次方 n += 1; } sum += temp; System.out.println(sum); }