为什么24*60*60*1000*1000除以24*60*60*1000在Java中不等于1000?
Jon*_*eet 60
因为乘法溢出32位整数.在64位中它没关系:
public class Test
{
public static void main(String[] args)
{
int intProduct = 24 * 60 * 60 * 1000 * 1000;
long longProduct = 24L * 60 * 60 * 1000 * 1000;
System.out.println(intProduct); // Prints 500654080
System.out.println(longProduct); // Prints 86400000000
}
}
Run Code Online (Sandbox Code Playgroud)
显然,在乘法溢出后,除法不会"撤消"溢出.