14. Recursion
Activity 1: Calculating the Fibonacci Sequence
Solution
- Create a class named
Fibonacci. - Create a static method called
fibonaccito calculate the Fibonacci sequence for a given number. If the input number is greater than1, this method will call itself.public static int fibonacci(int number) { if (number == 0) { return number; } else if (number == 1) { return 1; } else { return (fibonacci(number - 1) + fibonacci(number - 2)); } }If the input number is
0or1, this method returns the input number (0or1, respectively...