package com.Summer_0424.cn; /** * @author Summer * 计算1+1/3+1/5+1/7+1/9+.......+1/21 * */ public class Test08 { public static void main(String[] args) { double sum = 0.0; for (int i = 1; i <= 21; i+=2) { sum = sum + 1.0/i;//因为i为整数,计算结果为整数,所以用1.0 } System.out.println(sum); } }