Int i = 99 works, however int i = 099 does not work

In Java, I noticed that when I write

int i = 99; 

It works great. However when i say

 int i = 099; 

I get an exception:

 java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any> 

In my IDE, I see a red dot saying integer number too large: 099 .

Why is this not compiling? Isn't 099 equivalent to 99?

+4
source share
2 answers

Any leading 0 will cause Java to interpret the number as an octal number. So 010 is actually 8 .

 System.out.println(010); 

CONCLUSION:

 8 

And as you know, 8 and 9 not allowed in octal number.

+14
source

This is an octal number. Octal numbers are prefixed with 0 to distinguish them from other values, such as decimal and hexadecimal.

+6
source

All Articles