regarding leading zero in integer value

后端 未结 3 1720
野性不改
野性不改 2020-12-04 02:33

I have below code

int a = 01111;
System.out.println(\"output1 = \" + a);
System.out.println(\"output2 = \" + Integer.toOctalString(1111));

3条回答
  •  有刺的猬
    2020-12-04 03:20

    System.out.println("output2 = " +Integer.toOctalString(1111));
    

    Is converting the decimal string 1111 to an octal string: 2127.

    The decimal value of the octal 1111, is 585 - as expected, the result is expected, you don't get the same values because the two statements do different things.

    A correct test will be:

    System.out.println("output2 = " +Integer.toOctalString(a));
    

    Which will give you, as expected, 1111

提交回复
热议问题