长整数

阅读下面的代码

import java.util.*;
import java.math.*;
public class Third{
        public static void main(String[] args){
                final long VALUE = 24 * 60 * 60 * 1000 * 1000;
                System.out.println(VALUE);
        }
}

这是计算一天的微秒数,是否正确?

输出:500654080

这是不是一天的毫秒数呢?

继续看下面的代码:

import java.util.*;public class Third{
        public static void main(String[] args){
                final long VALUE = 24L * 60 * 60 * 1000 * 1000;
                System.out.println(VALUE);
        }
}

输出:86400000000
原来第一段代码已经被截了,因为24,60,1000都是int型,因此表达式会是int,之后再向上转型为long。



posted on 2015-03-27 08:11  琼华  阅读(178)  评论(0编辑  收藏  举报

导航