Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem: The Fibonacci class Your output should look like this: Specifications: In addition to the main method, you need two methods to do this. fibonacciIterative:

Problem: The Fibonacci class

Your output should look like this:

image text in transcribed

image text in transcribed

Specifications:

In addition to the main method, you need two methods to do this.

fibonacciIterative: which calculates the Fibonacci numbers using iterations

fibonacciRecursive: which calculates the Fibonacci numbers using recursions.

main Method

a) The main method should first create a Scanner object.

b) It will then read in from users input an integer number num, indicating how many Fibonacci numbers in the sequence the program is expected to compute and output. For example, if the user input 6, it means the program is expecting the first 6 numbers in the Fibonacci sequence.

c) The main method will introduce a loop and calls the fibonacciIteraive method to achieve each of these num numbers, and output them. Please output all these numbers in one line, separated by a space.

d) The main method then will also introduce a loop and calls the fibonacciRecursive method to achieve each of these num numbers and output them. Please output all these numbers in one line, separated by a space.

e) Iterations and recursions should generate the same sequence of numbers

I'm kinda stuck on the fibonacciIterative Method. some comments on this would help alot

fibonacciIterative Method

You can figure out your own way to calculate this Fibonacci number or follow the following pseudocodes.

previous = 0

last =1

next =1

repeat n times

previous = last

last = next

next = last + previous

return previous

fibonacciRecursive Method

The definition of Fibonacci numbers is internally recursive. Please follow the formula as mentioned above, and use recursions to compute a specific number in the Fibonacci sequence.

The same as the fibonacciIteraive method, the fibonacciRecursive also accepts one parameter (suppose it is n), which indicates the (n+1)-th

Please enter a number: 10 The first 10 numbers in Fibonacci sequence using iteration: 0112 3 5 8 13 21 34 The first 10 numbers in Fibonacci sequence using recursion: 0112 3 5 8 13 21 34 Please enter a number: 10 The first 10 numbers in Fibonacci sequence using iteration: 0112 3 5 8 13 21 34 The first 10 numbers in Fibonacci sequence using recursion: 0112 3 5 8 13 21 34

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions