Question: Modify Listing 18.2, ComputeFibonacci.java, so that the program finds the number of times the fib method is called. Listing 1 import java.util.Scanner; 2 3 public
Modify Listing 18.2, ComputeFibonacci.java, so that the program finds the number of times the fib method is called.
Listing

![method */ public static void main(String] args) { // Create a Scanner](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2022/11/636a736b73f75_747636a736b63f3a.jpg)
1 import java.util.Scanner; 2 3 public class ComputeFibonacci { 4 /** Main method */ public static void main(String] args) { // Create a Scanner Scanner input = new Scanner(System.in); System.out.print("Enter an index for a Fibonacci number: "); int index - input.nextInt(); 10 11 12 13 14 15 16 17 18 19 // Find and display the Fibonacci number System.out.println("The Fibonacci number at index " + index + " is " + fib(index)); /** The method for finding the Fibonacci number */ public static long fib(long index) { if (index == 0) // Base case return 0; 20 else if (index == 1) // Base case return 1; else // Reduction and recursive calls return fib(index - 1) + fib(index - 2); 21 22 23 24 25 } Enter an index for a Fibonacci number: 1 pteter The Fibonacci number at index 1 is 1 Enter an index for a Fibonacci number: 6 Jerter The Fibonacci number at index 6 is 8 Enter an index for a Fi bonacci number: 7 -Erter The Fibonacci number at index 7 is 13
Step by Step Solution
3.28 Rating (160 Votes )
There are 3 Steps involved in it
Output Enter an index for the Fibonacci number 7 Fibonacci number at index 7 is 13 The number of tim... View full answer
Get step-by-step solutions from verified subject matter experts
