سؤال

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