Question

How to handle 1000 digit number? Anyone can explain it?

My code;

 Long sum = 1L;
 ...

 if (String.valueOf(sum).length() == 1000) {
    ...
 }

But not working, anyone can explain it?

Was it helpful?

Solution

Use the class BigInteger, it can handle arbitrary long numbers (that is, as big as computer memory allows).

Link: http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html

OTHER TIPS

Use a BigInteger instead. See the documentation here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top