菜鸟日记—1月22日
什么是递归?
就是不断调用自身
- 1.找重复: 找子问题 比如求n的阶乘子问题是–求n-1的阶乘
- 2.找变化: 变化的量作为参数
- 3.找边界: 出口 在何时结束
案例一:求n的阶乘
static int f1(int n){
if (n == 1){
return 1;
}
return n * f1(n - 1);
}
public class 递归基础练习 {
public static void main(String[] args) {
System.out.println(f1(