Reputation: 3974
I am trying to assign a value to a long variable but eclipse shows compile error. Can anyone work it out what is wrong with this? I have check and am assured that the value is in long's range.
public static void main(String[] args) {
**long num = 600851475143;**
for(long i = num/2; i<1; i--) {
if(num%i == 0 && isPrime(i) == true) {
System.out.println(i);
break;
}
}
}
Upvotes: 0
Views: 1265
Reputation: 354714
You have to append L
to the literal to tell the compiler it's a long
. Integer literals in Java are int
by default; since the number you entered doesn't fit in an int
, the compiler complains.
Upvotes: 3