/**
* 有一列數,[1,1,2,3,5,8,13,21......]. 求第n項的值.請用java寫出求第n項值的方法
* @author lenovo
*
*/
public class QiuZhi {
public static void main(String[] args) {
int i=6;
int num=sortNum(i);
System.out.println(num);
}java
private static int sortNum(int i) {
int sum=0;
int evalation=0;
if(i>0&&i<3){
evalation=1;
}
else{
evalation=sortNum(i-1)+sortNum(i-2);
}
sum=sum+evalation;
return sum;
}.net
}
get