[英]long variable is not accepting a value
I am trying to assign a value to a long variable but eclipse shows compile error. 我正在尝试为长变量赋值,但是eclipse显示编译错误。 Can anyone work it out what is wrong with this?
谁能弄清楚这是怎么回事? I have check and am assured that the value is in long's range.
我已检查并确信该值在long范围内。
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;
}
}
}
You have to append L
to the literal to tell the compiler it's a long
. 您必须在文字后面加上
L
来告诉编译器它很long
。 Integer literals in Java are int
by default; Java中的整数文字默认情况下为
int
; since the number you entered doesn't fit in an int
, the compiler complains. 由于您输入的数字不适合
int
,因此编译器会抱怨。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.