The Fibonacci sequence is the series of numbers 1, 1, 2, 3, 5, 8, 13, 21, and

Question:

The Fibonacci sequence is the series of numbers 1, 1, 2, 3, 5, 8, 13, 21, and so on. The last number in the Fibonacci sequence is always the sum of the preceding two numbers. For example, 13 is the sum of 5 and 8, and 21 is the sum of 8 and 13. The sequence describes the way that many things in nature grow, as well as the way they decay. Write an application that accepts a positive ending value from the user; then, using a recursive method, display the Fibonacci sequence starting with 1 up to the requested ending value. Include the requested ending value if the value is part of the Fibonacci sequence. In other words, if the user enters 4 for the ending value, display 1 1 2 3, and if the user enters 5, display 1 1 2 3 5. Note that the solution to this problem has two base cases—when the ending number is 1 and when it is 2. In the two base cases, 1 is returned. Save the file as FibDemo.java.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  answer-question

Java Programming

ISBN: 9780357673423

10th Edition

Authors: Joyce Farrell

Question Posted: