标签:style blog color ar java for sp div on
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); } }
求2/1+3/2+5/3+8/5+13/8...前20项之和
标签:style blog color ar java for sp div on
原文地址:http://www.cnblogs.com/chuluofanchen/p/4039824.html