递归
5!
1.边界条件:边界
2.前阶段:
3.返回阶段 n*(n-1)
栈
练习1.阶乘
package com.xiyue.method;
public class Demo07 {
//2! 2*1 3! 3*2*1 5! 5*4*3*2*1
public static void main(String[] args) {
System.out.println(f(7));
}
public static int f(int n){
if(n==1){
return 1;
}else {
return n*f(n-1);
}
}
}
练习2:报错
package com.xiyue.method;
public class Demo06 {
public static void main(String[] args) {
Demo06 test = new Demo06();
test.test();
}
public void test(){
test();
}
}