code:
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);
}
}
This prints :
2160000000
-2134967296
Why?
Thanks for all the replies.
Is the only way to use L after the number?
I have tried the (long)24*1000*3600*25 but this is also negative.
To explain it clearly,
In the above statement are actually
intliterals. To make treat them as alongliteral you need to suffix those withL.Caveat, a small
lwill suffice too, but that looks like capitalIor1, sometimes. CapitalIdoesn’t make much sense here, but reading that as1can really give hard time. Furthermore, Even sufficing a single value withLwill make the resultlong.