20-方法递归

public class Demo06 {
    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 @ 2023-02-06 12:58  佩德罗帕斯卡  阅读(11)  评论(0)    收藏  举报