下列程序的输出结果,为什么System.out.println(Long.toHexString(0x100000000+0xcafebabe));

解决方案 »

  1.   

    Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    The literal 0x100000000 of type int is out of range
      

  2.   

    test.java:3: 过大的整数: 100000000
                    System.out.println(Long.toHexString(0x100000000+0xcafebabe));
                                                        ^
    1 错误
      

  3.   

    报错,原因:0x100000000 未加任何后缀,其为 int 类型,如果是 int 的话,0x 后面最多只能有八位,因为 int 类型采用 8 个字节来表示的,要让其正确只要改成:System.out.println(Long.toHexString(0x100000000L+0xcafebabeL));加个“L”采用 long 型数据来表示就可以了。