1.循环
public class T009 {
public static void main(String[] args){
System.out.println(fibonacci(3));
}
public static long fibonacci(int n){
int[] result = {0,1};
if(n<2)
return result[n];
long fibminOne=1;
long fibminTwo=0;
long fibN = 0;
for(int i =2;i<=n;i++){
fibN = fibminOne+fibminTwo;
fibminTwo=fibminOne;
fibminOne=fibN;
}
return fibN;
}
}