求2/1+3/2+5/3+8/5+13/8...前20项之和
package com.exercise.coreJava; /** *求2/1+3/2+5/3+8/5+13/8...前20项之和 */ public class Sum { public static void main(String[] args) { double sum = 0; double fenZi = 2.0, fenMu = 1.0; for (int i = 1; i <= 20; i++) { sum += fenZi / fenMu; fenMu = fenZi; fenZi += fenMu; } System.out.println("sum="+sum); } }