楚落凡尘

求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);
    }
}

 

posted on 2014-10-21 11:04  楚落凡尘  阅读(1562)  评论(0编辑  收藏  举报

导航