You want 1, 1, 2, 3, 5, 8, ...
Step by Step:
1) Write the class and main method headers and compile.
2) Create a variable for first and second, and set each to 1 and print them. Compile and run.
3) There is only one loop in this problem. You want it to repeatedly add the two numbers that were last in the sequence and print that total. You want it to repeat 10 times (since you already printed 2 of the 12 numbers). Create a for loop to print 10 times. Have it do nothing inside the for loop brackets. Compile and run.
4) Write this pseudocode inside the for brackets because this is what you want to repeat:
// Add the two numbers you changed and put them into a holding variable
// Print the sum
// Move the most recent variable value to the second most recent variable.
// Move the sum to the most recent variable
// (Note: You did the last two steps so the loop will find the two most recent
numbers in its variables when it starts again.
5) Code the first line of pseudocode only (without thinking about anything
else) and compile. Keep doing this for all 4 lines.
Pseudocode for final version:
public class Fib
{
public static void main()
{
// create three variables
and set two of them to 1
// loop of printing sum
of last two and then sliding variables back so they contain the last two again
}
}