Luffy Singh Luffy Singh - 1 year ago 120
Java Question

The constructor BigInteger(long) is not visible

So I'm creating a factorial program using BigInteger class. But I keep getting the above error.

public static BigInteger fact(long n){
BigInteger result = BigInteger.ONE;
for(int i = 1; i <= n; ++i){
result = result.multiply(new BigInteger(i));
return result;

I already found the fix which is just add an empty string with result.

result = result.multiply(new BigInteger(i + ""))

My question is, why do we have to add that empty string ?

Answer Source

As per oracle docs, BigInteger does not have any constructor that takes int as an argument

Secondly you should use BigInteger.valueOf(i); instead of new BigInteger(i + "")

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download