twz1015

递归

递归就是A方法调用A方法,自己调用自己

public static void main(String[] args) {
System.out.println(f(5));
}
public static int f(int n){
if (n==1){
return 1;
}else {
return n*f(n-1);
}
}

f(5)>f(4)>f(3)>f(2)>f(1)=1再依次回去完成递归

posted on 2023-03-19 14:25  小谭吖  阅读(11)  评论(0编辑  收藏  举报

导航