Nope, just re-assign it to the same variable. The operation will return a new BigInteger already.
BigInteger a = new BigInteger("1");
a = a.add(a);
Type: Posts; User: helloworld922
Nope, just re-assign it to the same variable. The operation will return a new BigInteger already.
BigInteger a = new BigInteger("1");
a = a.add(a);
I would recommend against using BigDecimal for this kind of operation, us a BigInteger instead.
Second, you're update loop never re-assigns i. BigDecimals and BigIntegers are immutable and need to...
I don't see why you would be running out of memory, 100! should fit in ~66 bytes, and even in it's string representation is ~158 characters long.
The JVM's default heap size is quite "small"...
Using BigDecimals and BigIntegers in Java has always been a pain.
You're last bit of code is actually computing sum = sum * sum * i, not sum = sum * i
That's probably the easiest method for isolating decimal digits in a BigDecimal.
What overall problem are you trying to solve? Perhaps there's a better way to solve that.