/*
写一个函数,输入n,求斐波那契(Fibonacci)数列的第n项。
*/
import java.util.*;
public class Class9 {
public int findFib(int a){
int sum = 1;
if(a < 0){
throw new RuntimeException("输入的数据不符合要求");
}
if(a == 0){
return 0;
}
if(a == 1){
return 1;
}
int b = 0;
int c = 1;
if(a > 1){
for(int i = 2; i <= a; i++){
sum = b + c;
b = c;
c = sum;
}
}
return sum;
}
public static void main(String[] args) {
Class9 c = new Class9();
System.out.println(c.findFib(0));
System.out.println(c.findFib(1));
System.out.println(c.findFib(2));
System.out.println(c.findFib(3));
System.out.println(c.findFib(4));
System.out.println(c.findFib(5));
}
}