How can I store a number with 10^6 digits in Java?
Would BigInteger be the most appropriate while considering performance issues like memory and speed
pradeep_java
0
Newbie Poster
Recommended Answers
Jump to PostJust declaring the variable as int is enough in this case since range of int is 2^32(=4294967296) which is far more than 10^6.
Refer range of primitive data types once.
Jump to Postharinath, he is looking for how to store a number with 10^6 digits, not 10^6 itself.
Jump to PostOh...shocked.. I think i dint read the question correctly.. I thought it is 10^6 number to be stored...
Is the OP really asking about 10^6 digits to be stored ..? Ohh my god..
Then , i think it looks like quite impractical to me.
He can store that …
Jump to PostYes, and that should be more than enough? What you need to do is to deal with operation.
// for example class MyMillionDigit { private char[] digits; // constructor1 public MyMillionDigit() { digits = new char[1000000]; ... } // constructor2 public MyMillionDigit(String number) { digits = new …
Jump to PostBigInteger holds arbitrarily large integers as binary values (the implementation uses an array of ints to provide whatever number of bits are required). I can't imagine that there would be any faster way to hold or do arithmetic on giant numbers on an ordinary computer, and certainly it's the most …
All 19 Replies
harinath_2007
56
Posting Whiz
bibiki
18
Posting Whiz
harinath_2007
56
Posting Whiz
mKorbel
274
Veteran Poster
hfx642
Taywin
312
Posting Virtuoso
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Taywin
312
Posting Virtuoso
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Taywin
312
Posting Virtuoso
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Taywin
312
Posting Virtuoso
pradeep_java
0
Newbie Poster
pradeep_java
0
Newbie Poster
JeffGrigg
170
Posting Whiz in Training
Delocaz
0
Newbie Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
JeffGrigg
170
Posting Whiz in Training
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.