Description:
Print the first 10 terms of the Fibonacci sequence.
Print the first 10 terms of the Fibonacci sequence.
Java Code
public class Fibonacci {
public static void main(String[] args) {
int n = 10, a = 0, b = 1;
System.out.print(a + " ");
for (int i = 1; i < n; i++) {
System.out.print(b + " ");
int next = a + b;
a = b; b = next;
}
}
}
Expected Output
0 1 1 2 3 5 8 13 21 34