public class test2 {
public static BigInteger getResult(int n) {
// 阶乘对整数才有意义
if (n < 0) {
throw new IllegalArgumentException();
//return -1;
}
// 0!=1,(0 的阶乘是存在的)
if (n == 0) {
return BigInteger.ONE;
}
// if (n < 2)
// return n * 1;
return BigInteger.valueOf(n).multiply(getResult(n - 1));
}
public static void main(String[] arg) throws Exception {
test2 t = new test2();
BigInteger n = t.getResult(10100);
}
}
递归n的阶乘
最新推荐文章于 2021-03-26 13:33:07 发布