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?

有帮助吗?

解决方案

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

其他提示

Use a BigInteger instead. See the documentation here.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top