Due date: Wednesday, March 4, 2020.
Objective: To use the for loop in Java.
The Fibonacci sequence is a sequence of number where each new one is the sum of the previous two. For example, the first 10 Fibonacci numbers are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
Create a Java project in Eclipse called hw7 and in it, a class called Fibonacci containing the main method.
a. Write a program that prints out the first 15 Fibonacci numbers. Use a for loop with a simple range between 0 and 15 for this. Before the loop, declare integer two variables, f1 and f2, initialized with 0 and 1. Then in the loop, do the following:
f = f1 + f2; f1 = f2; f2 = f; output f;Test the program to make sure it works.
b. Modify the program to add an integer n. Then ask the user hw many Fibonacci numbers they want to display, and input the value in n. Modify the loop to use n as the upper bound of the range.
Add an example of running the program as comments at the end of the code.
Upload the lab and homework .java files: Fraction.java and Fibonacci.java, to Canvas in Assignments - Homework 7.