Write a recursive function in java named fib that will accep
Write a recursive function in java named fib that will accept one int parameter greater than or equal to one, then calculate the Fibonacci sequence of that number.
Formula: Fn = Fn - 1 + Fn - 2. Please do not use loops. Also, this is only my second java class so please keep answer simple enough. Thanks
Solution
public int fib(int n)
{
if(n==0)
return 0;
else if(n==1)
return 1;
else
return fib(n-1)+fib(n-2);
}
