2013-02-18 48 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