Question: Task 2 : Test the Recursive Method You are also given a file called TestFib.java, which will help you test the fib 1 method. This
Task : Test the Recursive Method
You are also given a file called TestFib.java, which will help you test the fib method. This
file asks the user for an integer and calls the fib method to compute the corresponding
Fibonacci number.
Test with small numbers, then larger ones. You'll notice the method becomes slow for
larger numbers because it makes many repeated recursive calls.
To understand this, add a print statement in fib to display when a call is being made
egIn fib if calculating fib Run the program again to see how often values are
recalculated.
Notice how fib needs fib and fib and fib also needs fib This repetition
makes it inefficient
import java.util.Scanner;
public class TestFib
public static void mainString args
int n fib;
Scanner scan new ScannerSystemin;
System.out.printEnter an integer: ;
n scan.nextInt;
fib Fib.fibn;
System.out.printlnFib n is fib;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
