Fibonacci sequence
public class Fibonachi {
public static void printFibonachi(int n) {
int cur = 0;
int next = 1;
for (int i = 0; i < n; i++) {
System.out.print(cur + " ");
int tmp = next;
next += cur;
cur = tmp;
}
System.out.println();
}
public static void main(String[] args) {
int n = Integer.parseInt(args[0]);
printFibonachi(n);
}
}
Comments
Leave a comment