code:
public class Main{
public static void main(String[] a){
long t=24*1000*3600;
System.out.println(t*25);
System.out.println(2
In the first case you are printing a long
but in the second, you are printing it as int
.
And int
has a range from: -2^31 to 2^31 - 1 which is just below what you are calculating (int max: 2147483647 you: 2160000000) so you overflow the int to the negative range.
You can force the second one to use long
as well:
System.out.println(24L*1000*3600*25);