package digui_1;
/*
* 需求:用递归求下列数列的第二十项的值:
* 1,1,2,4,7,13,24...
*/
public class DiGuiDemo_1 {
public static void main(String[] args) {
int n = 20;
System.out.println(shulie(n));
}
public static int shulie(int n){
if(n==1||n==2){
return 1;
} else if(n==3){
return 2;
}
else {
return shulie(n-1)+shulie(n-2)+shulie(n-3);
}
//return n;
}
}
|