解析长到负数 [英] parse long to negative number
本文介绍了解析长到负数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码:
public class Main{
public static void main(String[] a){
long t=24*1000*3600;
System.out.println(t*25);
System.out.println(24*1000*3600*25);
}
}
打印:
2160000000
-2134967296
为什么?
感谢所有回复。
这是在数字后使用L的唯一方法吗?
Is the only way to use L after the number?
我试过(长)24 * 1000 * 3600 * 25
但这也是否定的。
I have tried the (long)24*1000*3600*25
but this is also negative.
推荐答案
要清楚解释,
System.out.println(24*1000*3600*25);
在上面的语句中实际上是 int
literals 。要将它们视为 long
字面值,您需要为 L
后缀。
In the above statement are actually int
literals. To make treat them as a long
literal you need to suffix those with L
.
System.out.println(24L*1000L*3600L*25L);
警告,一个小的 l
也足够了,但有时看起来像大写我
或 1
。资本我
在这里没有多大意义,但读到 1
确实会给你带来困难。此外,即使用 L
填充单个值,结果 long
。
Caveat, a small l
will suffice too, but that looks like capital I
or 1
, sometimes. Capital I
doesn't make much sense here, but reading that as 1
can really give hard time. Furthermore, Even sufficing a single value with L
will make the result long
.
这篇关于解析长到负数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文