package com.bohua.test;
/**
* 当你用每天的毫秒数来整除每天的微秒数时,除数中所有的因子都被约掉了,剩下 1000
* @author Administrator
*
*/
public class LongDivision{
public LongDivision() {
test1();
test2();
}
private void test2() {
final long MICROS_PER_DAY = 24 * 60 * 60 * 1000 * 1000l;
final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000;
System.out.println(MICROS_PER_DAY+" "+MICROS_PER_DAY/MILLIS_PER_DAY);
}
/**
* MICROS_PER_DAY和MILLIS_PER_DAY中int类型的数相乘得到的值仍然是int,然后int结果转换为long类型的时候,结果溢出
*/
private void test1() {
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+" "+MICROS_PER_DAY/MILLIS_PER_DAY);
}
public static void main(String args[]){
new LongDivision();
}
}
java 长整除问题
最新推荐文章于 2022-06-04 17:30:18 发布