啊哈添柴挑战Java1031. 斐波那契数列
作者:互联网
啊哈添柴——挑战
1031. 斐波那契数列
import java.util.Scanner;
/**
* @author yinglongwu
*/
//1031. 斐波那契数列
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n= scanner.nextInt();
if (n==1||n==2) {
System.out.println(1);
} else {
int[] a = new int[n];
a[0] = 1;a[1] = 1;
for (int i = 2; i < n; i++) {
a[i] = a[i-1]+a[i-2];
}
System.out.println(a[n-1]);
}
scanner.close();
}
}
标签:scanner,添柴,int,System,斐波,Java1031,那契,Scanner 来源: https://blog.csdn.net/qq_43594119/article/details/104924524