1

我遇到了麻烦,对此我无能为力。我想知道我怎么称呼这个方法?

public static BigInteger factorial(BigInteger n) {
    BigInteger result = BigInteger.ONE;

    while (!n.equals(BigInteger.ZERO)) {
        result = result.multiply(n);
        n = n.subtract(BigInteger.ONE);
    }

    return result;
}

对于 var=1,我明白了,我写了以下内容:

BigInteger kk = BigInteger.ONE;
System.out.println(factorial(kk));

但是,例如,我对如何数 61 感到困惑!

4

4 回答 4

3

尝试:

 BigInteger kk = new BigInteger("61");
 System.out.println(factorial(kk));
于 2013-02-18T13:13:54.593 回答
3

Java还有一个静态工厂方法

BigInteger kk = BigInteger.valueOf(61L);
于 2013-02-18T13:19:16.697 回答
2
BigInteger kk = new BigInteger("61");
System.out.println(factorial(kk));

API 是您的朋友:http ://docs.oracle.com/javase/1.4.2/docs/api/java/math/BigInteger.html

于 2013-02-18T13:13:38.213 回答
1

改变

BigInteger kk = BigInteger.ONE
System.out.println(factorial(kk));

BigInteger kk=new BigInteger("61");
System.out.println(factorial(kk));
于 2013-02-18T13:21:48.087 回答