The Fibonacci Sequence, Part 1. One of the most famous number sequences in mathematics, the Fibonacci sequence, has a recursive definition. Write a recursive method to calculate the nth Fibonacci number. In your main method, ask for n, and call your method to calculate it. Your method signature must be public static int fib(int n). The formula for the Fibonacci sequence is: fib(n) = fib(n - 1) + fib(n - 2).
The Fibonacci Sequence, Part 2. In a new class, modify your main method code from part 1 to create an array of the first n Fibonacci numbers. You will need a loop for this, but do not change the recursive method! Your main method should ask for the value of n, and calculate all values from fib(1) to fib(n). Note: fib(1) = 1 and fib(2) = 1, but you're using array indexes!
Recursive Printing. Create a recursive method, printUp(int n) to print the following pattern for any n > 0 rows: (this shows n = 5)
*
* *
* * *
* * * *
* * * * *
Also create a recursive method, printDown(int n) to print the following pattern for any n > 0 rows: (this shows n = 5)
* * * * *
* * * *
* * *
* *
*
Write a third recursive method, if possible, called printBoth(int n) to print both patterns at the same time, without calling printUp or printDown. The output should look like this for n = 5:
*
* *
* * *
* * * *
* * * * *
* * * * *
* * * *
* * *
* *
*
Your main method should ask for the value of n and call each method in order. Your methods in this lab must be recursive.