Loading...
Loading...
Loading...
The Fibonacci series starts 0, 1, and each next term is the sum of the two before it: 0, 1, 1, 2, 3, 5, 8, ... Read n and print the first n terms.
long.Example
Input
8
Output
0 1 1 2 3 5 8 13
0 1 1 2 3 5 8 13.
Try the problem first. Open one hint at a time.
Keep only the last two terms in two variables, a and b.
Each round print a, then move forward: the new a is b, and the new b is a + b. Use a third variable for the sum.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor