Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

integer too large???

Status
Not open for further replies.

Ito2233

MIS
Sep 2, 2003
77
US
I'm trying to assign values in the billion range to two LONG variables. The message I get from the compiler is:
"Integer number too large", in reference to the two large numbers I try to assign. Now, long integers can hold values much larger than the ones I'm trying to assign. So why am I getting this error? THANKS!

.....................................
class PseudoRandom {
public static void main (String[] args) {
long a = 3141592621, m = 10000000000;
int c = 1;

for (int x = 1; x <= 101; x++) {
System.out.println(x);
x = (a * x + c) % m;
}
}
}
 
class ps {
public static void main (String[] args) {

long a = 3141592621L, m = 10000000000L;
int c = 1;
long y;
for (int x = 1; x <= 101; x++) {
y = (a * x + c) % m;
System.out.println("!"+y);
}

}
}
 
Well, while I'm not getting the compile error anymore, I'm getting strange results. Some of the numbers printed are negative integers. Is a narrowing primitive conversion going on?
Thanks
 
If you are casting a long to an int, then most likely.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top