The Fibonacci sequence is a sequence of numbers such that the first two numbers are 0 and
Question:
The Fibonacci sequence is a sequence of numbers such that the first two numbers are 0 and 1, and each successive number is the sum of the two previous numbers. Thus, here are the first nine numbers in the Fibonacci sequence:
0 1 1 2 3 5 8 13 21
The third number is 1 because the previous two numbers, 0 and 1, add up to 1. The fourth number is 2 because the previous two numbers, 1 and 1, add up to 2.
Provide a code fragment that prints the Fibonacci sequence numbers for the numbers less than 25 (i.e., the numbers shown above). Your code fragment must consist of just a for loop header terminated by a semicolon—nothing else. Use comma-separated initialization and update components. Feel free to use the following as a start for your for loop:
for (int m=0, n=1, temp;
By the way, we recommend that you avoid using code like this for your real programs. This exercise is just for fun (fun for a hacker, anyway ).
Step by Step Answer:
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean