long value with 0 on left

后端 未结 5 868
星月不相逢
星月不相逢 2020-12-21 16:47

Why this behavior happens?

long value = 123450;
System.out.println(\"value: \" + value); 

value: 123450

 

long         


        
5条回答
  •  轮回少年
    2020-12-21 16:58

    This feature dates back to the early 'C' days. A leading '0' is for octal, a leading '0x' is for hexidecimal. It has been proposed that '0b' be for binary numbers for JDK 7.

    You can parse such a number with Integer.decode(String) which also accepts a leading '#' as a hexi-decimal number.

提交回复
热议问题