编写求阶乘

题目:编写一个类Computer,类中求阶乘

package Test;

public class Computer {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
    }
    public static int getFac(int n) {
        if(n == 1|| n==0)
            return 1;
        else
            return n*getFac(n-1);
    }
}

package Apppackage;

import Test.Computer;

public class app {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Computer computer = new Computer();
        int total = computer.getFac(6);
        System.out.println(total);
    }
}

 

posted @ 2019-09-18 13:54  James_Harden  阅读(169)  评论(0编辑  收藏  举报