parse long to negative number

前端 未结 7 1567
北恋
北恋 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:28

    To explain it clearly,

    System.out.println(24*1000*3600*25);
    

    In the above statement are actually int literals. To make treat them as a long literal you need to suffix those with L.

    System.out.println(24L*1000L*3600L*25L);
    

    Caveat, a small l will suffice too, but that looks like capital I or 1, sometimes. Capital I doesn't make much sense here, but reading that as 1 can really give hard time. Furthermore, Even sufficing a single value with L will make the result long.

提交回复
热议问题