繁体   English   中英

调用带有BigInteger参数的方法时遇到问题

[英]Problems invoking a method with a BigInteger parameter

我遇到了麻烦,对此我无能为力。 我想知道如何调用此方法?

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!。

尝试:

 BigInteger kk = new BigInteger("61");
 System.out.println(factorial(kk));

Java也有一个静态工厂方法

BigInteger kk = BigInteger.valueOf(61L);
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

更改

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

BigInteger kk=new BigInteger("61");
System.out.println(factorial(kk));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM