Java: Using "08" and "09" in an array -


how can store 08 , 09 int array? understand cannot due binary characteristics , have tried both...

0b08, 0b09 ... , ... 0b08, 0b09 no luck.

the following line of code ideally i'd have:

final int[] monthvaliddosinputs = {00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12}; 

here error...

convertdate.java:15: error: integer number large: 08 convertdate.java:15: error: integer number large: 09 

thanks!

when start literal integer 0, it's considered octal number, 1 uses base 8 rather base 10. means 8 , 9 not valid digits.

if really want leading 0 (i.e., octal), need like:

int[] monthvaliddosinputs = {000, 001, ..., 007, 010, 011, 012, 013, 014}; 

which gives decimal numbers 0 through 12, in octal.

however, if want keep them evenly spaced decimal, use 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 gain that. may use:

int[] monthvaliddosinputs = {0,1,2,3,4,5,6,7,8,9,10,11,12}; 

and done it. makes no difference compiler.


if you're looking use these check user input (where may enter 8 or 08 month), you're better off either:

  • using strings check against; or
  • reducing input integer (using integer.parseint(str,10)) there's no difference between 04 , 4.

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -