package homework;
public class SeriesSum {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//(1)
double fz = 2;
double fm = 1;
double sum = 0;
int i;
//(2)累加
for(i=1;i<=20;i++){
sum=sum+fz/fm; //第一项
fz = fz+fm;
fm = fz-fm;
}
//格式化输出
System.out.printf("%.2f",sum);
}
}
时间: 2024-10-20 08:35:22