Java How To -Fibonacci Sequence
How To Generate Fibonacci Sequence
Print the first 10 numbers of the Fibonacci sequence:
Example
int n1 = 0, n2 = 1, count = 10;System.out.print("Fibonacci: " + n1 + " " + n2);for (int i = 2; i < count; i++) { int n3 = n1 + n2; System.out.print(" " + n3); n1 = n2; n2 = n3;}// Output: Fibonacci: 0 1 1 2 3 5 8 13 21 34
