parse long to negative number

前端 未结 7 1563
北恋
北恋 2021-01-20 14:48

code:

public class Main{
    public static void main(String[] a){
        long t=24*1000*3600;
        System.out.println(t*25);
        System.out.println(2         


        
相关标签:
7条回答
  • 2021-01-20 15:47

    Integral literals are treated as type int by default. 24*1000*3600*25 is greater than Integer.MAX_VALUE so overflows and evaluates to -2134967296. You need to explicitly make one of them a long using the L suffix to get the right result:

    System.out.println(24L*1000*3600*25);
    
    0 讨论(0)
提交回复
热议问题