Java方法——递归

递归(栈)

 

 package method;
 
 public class Demon04 {
        //递归思想
    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);
        }
    }
 }
 

 

posted @ 2021-07-17 10:14  时间最考验人  阅读(66)  评论(0编辑  收藏  举报