3.长整除

代码:

package puzz; public class LongDivision { public static void main(String[] args) { // wrong final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000; final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000; System.out.println(MICROS_PER_DAY / MILLIS_PER_DAY); // right final long MICROS_PER_DAY1 = 24L * 60 * 60 * 1000 * 1000; final long MILLIS_PER_DAY1 = 24L * 60 * 60 * 1000; System.out.println(MICROS_PER_DAY1 / MILLIS_PER_DAY1); } }  

 

结果:

//5 //1000 

 

因为24 * 60 * 60 * 1000 * 1000是int相乘,溢出

 

操作大的数字的时候,千万注意溢出

你可能感兴趣的:(3.长整除)