Output: 1 1 2 3 5
Copy the code code as follows:
public class FibonaciTest {
public static void main(String[] args) {
Fibonacci(5);
}
public static void Fibonacci (int count) {
int[] num = new int[count];
num[0] = num[1] = 1;
for (int i = 2; i < count; i++) {
num[i] = num[i - 1] + num[i - 2];
}
for (int j = 0; j < count; j++){
System.out.print(num[j] + " ");
}
}
}