How can I keep 1 million digit in Java?

耗尽温柔 提交于 2019-12-11 11:07:48

问题


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".


回答1:


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.



来源:https://stackoverflow.com/questions/37081432/how-can-i-keep-1-million-digit-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!