有一分数序列2/1,3/2,5/3,8/5,13/8,21/13求出这个数列的前20项之和 32.66026079864164java编写
时间: 2023-12-13 15:55:33 浏览: 70
以下是Java代码实现:
```java
public static void main(String[] args) {
double sum = 0;
double a = 2, b = 1;
for (int i = 1; i <= 20; i++) {
sum += a / b;
double temp = a;
a = a + b;
b = temp;
}
System.out.println("前20项之和为:" + sum);
}
```
输出结果为:
```
前20项之和为:32.66026079864164
```
阅读全文