The literal of type int is out of range?
Hello, I've just started a new piece of code and am getting an error already:
The literal 600851475143 of type int is out of range
Code:
public class Problem3 {
public static void main (String args[]){
long y, x;
y=600851475143;
for (x=0,x<600851475143,x++){
}
}
}
The error is for the number:600851475143. Am I using long incorrectly?
Cheers!
Re: The literal of type int is out of range?
You're forgetting the "L" that needs to be appended to the end of a long literal:
Code:
public class Problem3 {
public static void main (String args[]) {
long y = 600851475143L;
for (long x = 0L; x < 600851475143L; x++) {
}
}
}
You're also forgetting to add spaces to your code. :)
edit: and semicolons in the for condition
Re: The literal of type int is out of range?
There are limits to the values that can be stored in the various numeric data types. You should read the Primitive Data Types Tutorial to understand them.
Beaten by the Fubarable...I'm going to bed!
Re: The literal of type int is out of range?