Solved

How to compare 2 more than 30 digit number in java

Posted on 2009-04-08
7
279 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
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 125 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
topping1 challenge 7 53
Java asynchronous logging 4 35
Free Alternative to JIRA 4 58
recursion example 16 71
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now