public static void main(String[] args) {
System.out.println(getNum(5));
}
public static int getNum(int num) {
if (num == 1) {
return 1;
} else if (num == 2) {
return 1;
} else {
return getNum(num - 1) + getNum(num - 2);
}
}
下面是求阶乘
public static void main(String[] args) {
System.out.println(getJi(4));
}
public static int getJi(int num) {
if (num==1){return 1;}
return num* getJi(num-1); //24
}