integer number too large

Posted on 2004-08-26
Last Modified: 2009-12-16
I tried to do this: private static long prime=5095271039;
why is this so? I thgt long gives value to 64bits? This value is obtained from BigInteger.

i want to work with the numbers arithmetically, some int, some BigInteger. DO I need to convert all of them to the same type?
Question by:QLJ
LVL 86

Expert Comment

ID: 11904294
You must use the methods of BigInteger for calcs
LVL 35

Assisted Solution

girionis earned 20 total points
ID: 11904301
If you have an int you should declare it as an int, otherwise declar its type. Try this:

private static long prime=5095271039L;

LVL 35

Expert Comment

ID: 11904310
> DO I need to convert all of them to the same type?

I am afraid you will be needed to do, yes.

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 86

Expert Comment

ID: 11904321
>>some BigInteger

If you have some that are BigInteger, then presumably there's a good reason (they're big), so if they *are* too big for long or int, then you must use BigInteger

Expert Comment

ID: 11905830
It is best to make all datatypes the largest datatype needed.  Kind of a pain, but it avoid a lot of problems that can result from the JVM overflowing calcluations, then converting the result to the larger type.  This doesn't throw any warnings or exceptions, you just get screwy results.
LVL 92

Accepted Solution

objects earned 30 total points
ID: 11907425
> DO I need to convert all of them to the same type?

Not at all, you just need to ensure that you cast appropriately.

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Receive file in Servlet 1 36
allStar challenge 1 41
groupSum6 challenge 6 35
eclipse formatting 6 41
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

705 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

18 Experts available now in Live!

Get 1:1 Help Now