Why is 08 not a valid integer literal in Java?

后端 未结 6 1032
清歌不尽
清歌不尽 2020-11-22 06:30

Why is 08 considered an out of range int but 07 and below are not?

6条回答
  •  眼角桃花
    2020-11-22 06:53

    In Java, if you are defining an int with a leading '0' denotes that you are defining a number in Octal.

    int a = 08 is giving out of range error because there is no any number '8' in Octal. Octal provides 0-7 numbers only.

    If you define a = 07 then it's not giving out of range error because the numbers '0' and '7' are within the Octal's range.

提交回复
热议问题