// Print out the first N Fibonacci numbers in the order:
// 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765
public static final void printFib(final int N) {
int f0 = 0;
int f1 = 1;
for (int i = 0; i < N; ++i) {
System.out.println(f0);
final int temp = f1;
f1 += f0;
f0 = temp;
}
}
No comments:
Post a Comment