Home / Expert Answers / Computer Science / solve-in-java-please-1-fibonacci-sequence-the-fibonacci-sequence-is-named-after-the-italian-ma-pa825

(Solved): Solve in Java please 1 Fibonacci Sequence The Fibonacci sequence is named after the Italian ma ...



1 Fibonacci Sequence
The Fibonacci sequence is named after the Italian mathematician Leonardo of Pisa, also known as Fibonacc

Solve in Java please

1 Fibonacci Sequence The Fibonacci sequence is named after the Italian mathematician Leonardo of Pisa, also known as Fibonacci. The steps for the for the Fibonacci sequence are to start with the and terms, which are 0 and 1 respectively, and to calculate the next term, sum the previous two terms. Using the initial numbers the term in the Fibonacci sequence is 1 . Now that you know the pattern, here are the through numbers in the Fibonacci sequence: . Now let's write a Fib class to help us find the Fibonacci number. Write the following functions in the Fib class: - public static int fibonacciRecursive(int ) - this will return the Fibonacci number as an int using a recursive approach. - public static int fibonacciIterative(int ) - this will return the Fibonacci number as an int using an iterative approach. Here are some test cases: Example Test Cases: - fibonacciRecursive(3) will return 2 - fibonacciRecursive(5) will return 5 - fibonacciIterative(8) will return 21 - fibonacciIterative(10) will return 55 Once you have your methods working, use the Scanner class to prompt for input in the main function of Fib. Hint: For a reminder on how to use Scanner class, the Scan.java file on Canvas is a good place to start. This example explains how to take ints as input. For example, to take in an integer for the Fibonacci functions, your Java code could be the following (in main): public static void main(String args[]) \{ System.out.println("Enter an integer n to get the n'th Fibonacci number:"); Scanner myScanner = new Scanner (System.in); int myScanner.nextInt () gets an integer from command line System.out.println("The "' th Fibonacci number using fibonacciRecursive is " fibonacciRecursive System.out.println("The " "'th Fibonacci number using fibonacciIterative is " fibonacciIterative


We have an Answer from Expert

View Expert Answer

Expert Answer


We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe