//大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项。 F(0)=0,F(1)=1, F(n)=F(n-1)+F(n-2)(n>=2,n∈N*)
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println(Fibonacci(n));
}
public static int Fibonacci(int n) {
//循环处理
if(n<=1){
return n;
}
int[] result = new int[n+1];
result[0] = 0;
result[1] = 1;
for(int i = 2;i<=n && i<=39;i++){
result[i] = result[i-1]+result[i-2];
}
return result[n];
//递归处理
if(n<=1){
return n;
}else{
return Fibonacci(n-1)+Fibonacci(n-2);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println(Fibonacci(n));
}
public static int Fibonacci(int n) {
//循环处理
if(n<=1){
return n;
}
int[] result = new int[n+1];
result[0] = 0;
result[1] = 1;
for(int i = 2;i<=n && i<=39;i++){
result[i] = result[i-1]+result[i-2];
}
return result[n];
//递归处理
if(n<=1){
return n;
}else{
return Fibonacci(n-1)+Fibonacci(n-2);
}
}