09 is not recognized where as 9 is recognized [duplicate]

岁酱吖の 提交于 2019-11-26 06:07:56

问题


This question already has an answer here:

  • Why is 08 not a valid integer literal in Java? 6 answers

I am using quartz for schedulling.

TriggerUtils.getDateOf(0,40,18,09,06);

it accept 5 parameter. (seconds, minutes, hours, daysOfMonth, month).

When i pass fourth parameter as \"09\". Eclipse give me error \"The literal Octal 09 (digit 9) of type int is out of range \".

But when i pass the fourth parameter as \"9\" instead of \"09\", it works.

Can anyone explain me this error?


回答1:


In java, if you are defining an integer, a leading '0' will denote that you are defining a number in octal

int i = 07; //integer defined as octal
int i = 7; // integer defined as base 10
int i = 0x07; // integer defined as hex
int i = 0b0111; // integer defined as binary (Java 7+)



回答2:


There is no 9 in Octal (what you get with a preceding 0). 0-7, only.




回答3:


When you precede a number with 0 ("09" rather than "9"), then Java (and C and many other languages) interpret the number to be in octal - base-8.

"09" is not a valid number in octal - any single digit can be a maximum of "7" (since in octal, numbers go from 0..7).




回答4:


Numbers that begin with the zero digit are treated as octal (base 8) literals, and 9 is not a valid octal digit.




回答5:


10 is how many digits you have, whereas 010 is is what you get if you don't count your thumbs.



来源:https://stackoverflow.com/questions/970039/09-is-not-recognized-where-as-9-is-recognized

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!