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 Postharinath, he is looking for how to store a number with 10^6 digits, not 10^6 itself.
Jump to PostHmm... How about using "char" array of size 10^6? A char is size of byte which should be more than enough to hold that many digits?
A Java char is 2 bytes.
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 …
Jump to PostHe did say "...considering performance issues like memory and speed".
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.