第五章第二十四题(数列求和)(Sum a series)
- *5.24(数列求和)编写程序,计算下面数列的和:
*5.24 (Sum a series) Write a program to compute the following summation:
- 参考代码:
package chapter05;
public class Code_24 {
public static void main(String[] args) {
double summation = 0;
for(int i = 1;i <= 97;i += 2)
summation += 1.0 * i / (i + 2);
System.out.println("The result of summation is " + summation);
}
}
- 结果显示:
The result of summation is 45.124450303050196
Process finished with exit code 0