2013-02-18 21 views
1

我遇到了麻烦,我无法做任何事情。我想知道我怎么称呼这种方法?使用BigInteger参数调用方法的问题

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

+1

我通过阅读答案第一.... – Kent 2013-02-18 13:17:03

回答

1

变化

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

BigInteger kk=new BigInteger("61"); 
System.out.println(factorial(kk)); 
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

+0

感谢明白的问题,我投了) – Leo 2013-02-18 13:16:24

+0

我做阅读API,好吧,我会更expirienced下一次 – Leo 2013-02-18 13:17:37

+0

如果你不确定如何构建一个对象,第一个端口是读取该对象的API并阅读构造函数部分 – cowls 2013-02-18 13:18:23

3

尝试:

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

谢谢,我投票了) – Leo 2013-02-18 13:15:15