Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a recursive method called fibonacci \"fib\" in Java, and include it in a p

ID: 3642127 • Letter: W

Question

Write a recursive method called fibonacci "fib" in Java, and include
it in a program to test it. Specifically, have your "main" method
read in a number, say, "n" and then call "fib" to compute the nth
Fibonacci number. Print the value returned by "fib."

Test your program with the following input values for n (among
others): 10, 20, 30, and 40.

Determine the largest Fibonacci number that can be computed
using an integer representation. In other words, what is the
largest value of n that can be input without causing fib to
experience integer overflow? i know its somewhere in the mid 40s...
OUTPUT'll BE MUCH APPRECIATED>>>>>thank You.....

Explanation / Answer

public class Fibonacci{
public static int fib(int n){
if (n==0) return 0;
else if (n==1) return 1;
else return (fib(n-1) + fib(n-2));
}
public static void main(String[] args)
{
System.out.println(fib(10));
System.out.println(fib(20));
System.out.println(fib(30));
System.out.println(fib(40));
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote