0

I am running following simple java code for arrays.

public class MyArray
{

    public static void main(String args[])
    {
        int ar[] =
        {
            08, 047, 06, 05, 04, 03, 02, 091
        };
     }
}

The error I got is

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type:

I know the error is because I wrote integer '8' as '08' & '91' as '091' (rest worked fine) as Netbeans showed the error of size too large. I want to know the reason behind it. Also when I print ar1, the value printed is 39 not 47.

Snippet from netbeans

Shivam Agarwal
  • 133
  • 1
  • 6
  • 4
    A leading zero is octal. See [the JLS](https://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.1). – Boris the Spider Oct 20 '17 at 10:14
  • 1
    If a number starts with `0` it's **octal** and thus must contain `0..7` digits only. Please, notice that `047` being *octal* is equal to `39` (decimal) `047 = 4 * 8 + 7 = 39 (decimal)`. – Dmitry Bychenko Oct 20 '17 at 10:14
  • Good Answer here https://stackoverflow.com/questions/35521278/printing-an-integer-in-java-that-have-zero-in-front-of-it/35521965#35521965 – Thomas Oct 20 '17 at 10:15
  • Number starts with 0 consider as octal number. That's fine, you already got the answer. Why do you want to add 0 in front of integer? There was already more similar questions found know. – Kumar Oct 20 '17 at 10:24

0 Answers0