/* 计算一个数组前二十个元素的和 */ public static voidmain(String[] args){
double n1 = 1;
double n2 = 1;
double fraction = n1/n2;
double Sn = 0;
for(int i=0;i<20;i++){
double t1 = n1;
double t2 = n2;
n1 = t1+t2;
n2 = t1;
fraction = n1/n2;
Sn += fraction;
}
System.out.print(Sn);
}
|