阶乘

import java.math.BigInteger;

public class Factorial {
    public static BigInteger bigInteger(int n) {
        BigInteger result = new BigInteger("1");
        if (n < 0) {
            System.err.println("n must be great than 0");
            return new BigInteger("-1");
        } else if (n == 0) {
            return new BigInteger("1");
        } else {
            for (int i = 1; i <= n; i++) {
                BigInteger num = new BigInteger(String.valueOf(i));
                result = result.multiply(num);
            }
            return result;
        }
    }

    public static void main(String[] args) {
        System.out.println("result = " + bigInteger(100));
    }
}

 

posted on 2016-06-17 18:03  AlphaGo1号  阅读(141)  评论(0)    收藏  举报

导航