My question is that, I want to multiply 2 number which has 1 million digit. When I tried to assign 1 million number to BigInteger, Compiler is giving to me error. The error is that:"constant string too long".
Asked
Active
Viewed 1,860 times
1
-
Does this help? https://stackoverflow.com/questions/12088436/what-does-biginteger-having-no-limit-mean – Carl Tashian May 06 '16 at 21:12
-
you have a one-million digit long String representing a number? What kind of calculation you're doing? I seem to be able to create a BigInteger instance with one million digits. – Renato May 06 '16 at 21:16
1 Answers
3
BigInteger
is indeed the way to store such large integers, although hundreds or a few thousands of digits are more typical use cases. However, Java class files have limitations that won't allow hard coding a literal number that large.
Instead, store the number in a file and read it at runtime. If the file contains a textual representation in decimal, hexadecimal, or some other base, you can read it into a String
and pass it to the BigInteger
constructor. If the file contains the raw bits, load it to a byte[]
and use a different constructor.