/** * @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); } }
时间: 2024-12-14 18:12:02