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

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

猜你喜欢

转载自blog.csdn.net/axiba01/article/details/81087571