Lab 12-12
public class Fibonacci {
public static double n0 = 1, n1 = 1, sum = 0;
public static double next() {
sum = n0 + n1;
n0 = n1;
n1 = sum;
return sum;
}
public static void main(String[] args) {
for (int i = 0; i <>
Fibonacci.next();
System.out.println("F(" + (i + 2) + ") = " + sum);
}
}
}
0 Comments:
張貼留言
<< Home