码迷,mamicode.com
首页 > 其他好文 > 详细

有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。

时间:2017-06-15 00:48:35      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:div   out   print   span   ati   string   log   author   nbsp   

/**
 * @author 有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。
 */
public class Sum {

    public static void main(String[] args) {
        double a = 1, b = 1, c = 0, s = 0;
        for (int i = 0; i < 20; i++) {
            c = a + b;
            s = s + c / a;
            b = a;
            a = c;
        }
        System.out.println(s);
    }

}

 

有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。

标签:div   out   print   span   ati   string   log   author   nbsp   

原文地址:http://www.cnblogs.com/lanseyitai1224/p/7011531.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!