When you start a literal integer with 0
, it's considered an octal number, one that uses base 8 rather than base 10. That means 8
and 9
are not valid digits.
If you really want a leading zero (i.e., octal), you would need something like:
int[] monthValidDosInputs = {000, 001, ..., 007, 010, 011, 012, 013, 014};
which gives you the decimal numbers 0
through 12
, but in octal.
However, if you want to keep them evenly spaced with decimal, just use a leading space instead of zero:
int[] monthValidDosInputs = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
// ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^ ^^
although I'm not sure you gain anything from that. You may as well just use:
int[] monthValidDosInputs = {0,1,2,3,4,5,6,7,8,9,10,11,12};
and be done with it. It makes no difference to the compiler.
If you're looking to use these to check user input (where they may enter 8
or 08
for a month), you're better off either:
- using strings to check against; or
- reducing their input to an integer (using something like
Integer.parseInt(str,10)
) so that there's no difference between 04
and 4
.