This program will take input as n and return the Fibonacci of that number.
5
Sample Output 1
5
Sample Input 2
13
Sample Output 2
233
Solution
import java.util.*;
class HelloWorld {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
System.out.println(fibo(n));
}
public static int fibo(int n) {
if(n==0||n==1)
{
return n;
}
int f1=fibo(n-1);
int f2=fibo(n-2);
return f1+f2;
}
}