代码原文:package com.**.java;
public class TestFens {
public static void main(String[] args)//main
{
int k =0;
double i = 2,j=1, sum =0, m=0;
for(k=1;k<20;k++){
m=i;
i=i+j;
j=m;
System.out.println("i="+i);
System.out.println("j="+j);
sum=sum+i/j;
System.out.println("sum="+sum);
}
}
}
不知道为什么输出结果会这样i=3.0
j=2.0
sum=1.5
i=5.0
j=3.0
sum=3.166666666666667
i=8.0
j=5.0
sum=4.7666666666666675
i=13.0
j=8.0
sum=6.3916666666666675
i=21.0
j=13.0
sum=8.007051282051282
i=34.0
j=21.0
sum=9.626098901098901
i=55.0
j=34.0
sum=11.24374595992243
i=89.0
j=55.0
sum=12.86192777810425
i=144.0
j=89.0
sum=14.479905306194137
i=233.0
j=144.0
sum=16.097960861749694
i=377.0
j=233.0
sum=17.715986612822654
i=610.0
j=377.0
sum=19.334023748101167
i=987.0
j=610.0
sum=20.95205653498641
i=1597.0
j=987.0
sum=22.570090982808093
i=2584.0
j=1597.0
sum=24.188124796208218
i=4181.0
j=2584.0
sum=25.806158851935773
i=6765.0
j=4181.0
sum=27.42419281510248
i=10946.0
j=6765.0
sum=29.042226813624282
i=17711.0
j=10946.0
sum=30.66026079864164
|
|