递归算法就是直接或间接调用自己的算法
public static void main(String[] args) {
int m = sum(9);
System.out.println(m);
}
public static int sum(int n) {
if (n <= 2)
return 1;
else {
return sum(n - 1) + sum(n - 2);
}
}
递归算法就是直接或间接调用自己的算法
public static void main(String[] args) {
int m = sum(9);
System.out.println(m);
}
public static int sum(int n) {
if (n <= 2)
return 1;
else {
return sum(n - 1) + sum(n - 2);
}
}