liyizhu

递归求6的阶乘(考虑int类型溢出)


编码

public class Factorial {
    public static void main(String[] args) {
        System.out.println(fac(6));
    }
    
    public static long fac(int n){
        if(n>1) {
            return n * fac(n-1);
        }else {
            return 1;
        }
    }
}

 

posted on 2019-03-22 01:38  liyizhu  阅读(666)  评论(0编辑  收藏  举报

导航