名稱:

星期一, 10月 24, 2005

Fibonacci

public class Fibonacci {
public Fibonacci() {
}

public static void main(String[] args) {
double f0 = 1, f1 = 1, f2 = 0, ratio = 0;
System.out.println("1" + " ratio is " + "?");
System.out.println("1" + " ratio is " + "1");
for (int i = 0; i < 100; i++) {
f2 = f0 + f1;
ratio = (double) f2 / f1;
f0 = f1;
f1 = f2;
System.out.println(f2 + " ratio is " + ratio);
}
}
}

0 Comments:

張貼留言

<< Home