Question: Modify Listing 18.2, ComputeFibonacci.java, so that the program finds the number of times the fib method is called. (Hint: Use a static variable and increment

Modify Listing 18.2, ComputeFibonacci.java, so that the program finds the number of times the fib method is called. (Hint: Use a static variable and increment it every time the method is called.)

Data from Listing 18.2,

1 1mport java.util.Scanner; 2 3 publ1c class ComputeFibonacci { 1** Main method

1 1mport java.util.Scanner; 2 3 publ1c class ComputeFibonacci { 1** Main method / publ1c static vo1d main(String[] args) { /I Create a Scanner Scanner input = new Scanner (System.in): System.out.print("Enter an 1ndex for a F1bonacc1 number: "): int index = input.nextInt (): 4 5 6 7 8 9 10 II Find and display the Fibonacci number Sy stem.out.printin("The F1bonacc1 number at index " + index + " 1s " + fib(index)): 11 12 13 14 15 1* The method for finding the Fibonacci number / publ1c static long fib(long index) { 1f (index == 0) IT Base case return 0; else 1f (index == 1) / Base case return 1; else 16 17 18 19 20 21 II Reduction and recursive calls return fib(index - 1) + fib(index - 22 23 24 25 }

Step by Step Solution

3.39 Rating (165 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import javautilScanner public class Exercise1807 static int count 0 public static void mainString ar... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction to Java Programming and Data Structure Questions!