?
Solved

How to compare 2 more than 30 digit number in java

Posted on 2009-04-08
7
Medium Priority
?
284 Views
Last Modified: 2012-05-11
Can i get the source code or logic to compare 2 more than 30 digit number?
0
Comment
Question by:gunjankhatri
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 12

Expert Comment

by:basav_com
ID: 24100716
Can you elaborate your question more..
0
 
LVL 25

Accepted Solution

by:
InteractiveMind earned 500 total points
ID: 24100851
Use the java.math.BigInteger class to store your numbers and compare them.
http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html
0
 
LVL 17

Expert Comment

by:Thomas4019
ID: 24101576
You could turn them both into Strings and compare them with their equals() method.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:isarasoo
ID: 24106000
Hi , I have a similar problem to this currently i got around it by loading the digits straight into a char array and then compare the outputs and it works but il rather have a simpler solution.

I tried the above methods suggesting to convert it to string, but that would only be possible if i can store the value as something initially i.e. long  num = 40 digits.

Just a question for InteractiveMind  how many digits can you assign to BigInteger.
sorry in advance if im not allowed to ask a counter question here

thanks
0
 
LVL 1

Expert Comment

by:isarasoo
ID: 24112405
I have just tested bigInteger class and it works fine for numbers over 30dig.  thanks InteractiveMind
0
 
LVL 17

Expert Comment

by:Thomas4019
ID: 24112526
I am fairly sure BigInterger is designed to hold unlimited amount of digitis. It should just keep allocating more memory.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question