Here is my main method, I am trying to call the Fibonacci sequence to tell me what number would be at the location the user inputs:
import java.util.Scanner; //import Scanner
public class Main {
public static void main(String[] args) {
System.out.println("enter number");
Scanner input = new Scanner(System.in);
int n = input.nextInt();
Fibonacci fibonacci_test = new Fibonacci();
fibonacci_test.Recursivefibonacci(n);
}
}
Here is my Fibonacci code that I have:
public class Fibonacci {
//Fn=F(n-1)+F(n-2)
//The recursive Fibonacci method
public int Recursivefibonacci(int n) {
if(n==0) {
return 0;
} if(n==1) {
return 1;
}else {
int fib = Recursivefibonacci(n-1)+Recursivefibonacci(n-2);
return fib;
}
}
}
I cannot get this thing to print anything. How can I fix this?