经典的斐波那契数列,形如: 0 , 1, 1, 2, 3, 5 ,8....求第n那个数
import java.util.Scanner;
public class Febonacci {
/**
* @param 斐波那契数列求第n个数字
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner console = new Scanner(System.in);
int n = console.nextInt();
System.out.println(febonacci(n));
}
private static int febonacci(int n) {
// TODO Auto-generated method stub
if(n==0)
return 0;
if(n==1)
return 1;
return febonacci(n-1)+febonacci(n-2);
}
}