• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The Literal Octal 08 of type int is out of range

 
RACHIT JAIN
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HashMap<Integer,String> monthMap = new HashMap<Integer, String>();

monthMap.put(01, "Jan");
monthMap.put(02, "Feb");
monthMap.put(03, "Mar");
monthMap.put(04, "Apr");
monthMap.put(05, "May");
monthMap.put(06, "Jun");
monthMap.put(07, "Jul");
monthMap.put(08, "Aug");
monthMap.put(09, "Sep");

monthMap.put(10, "Oct");
monthMap.put(11, "Nov");
monthMap.put(12, "Dec");

Is there any way we can resolve this error. I can take this as a string; assume I don�t want that solution.

Is there any way we can tell the compiler that is not an octal or something like that. I know in place of 08 I can take as 8, but that will not work in my case.

Thanks in advance!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is there any way we can tell the compiler that is not an octal or something like that. I know in place of 08 I can take as 8, but that will not work in my case.

Why are you using octal notation if you don't want octal numbers? You've already gone to the extra effort of telling the compiler that it is an octal number.
[ July 31, 2008: Message edited by: Paul Sturrock ]
 
Norm Radder
Ranch Hand
Posts: 1039
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer is NOT going to preserve your leading 0s.
Most conversion methods strip leading 0s so that 00000001 will end up as 1
 
Rob Spoor
Sheriff
Pie
Posts: 20559
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exactly. So why not just use 8 instead of 08.

If you need to 0 later on when printing, check out java.text.NumberFormat and java.text.DecimalFormat.
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An octal numeral consists of an ASCII digit 0 followed by one or more of the ASCII digits 0 through 7 and can represent a positive, zero, or negative integer.


Note that octal numerals always consist of two or more digits; 0 is always considered to be a decimal numeral-not that it matters much in practice, for the numerals 0, 00, and 0x0 all represent exactly the same integer value. - Java Spec
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Rachit]: I know in place of 08 I can take as 8, but that will not work in my case.

Why is that? Why does it matter whether there's a 0 in front or not?

I suspect that if this really is important for some reason, you'd be better off using a String "08" rather than an int.

I assume you don't actually want to be using octal notation here - but you've accidentally gone into octal without realizing it. Is that correct?
 
Krishna Manohar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
instead of 08, you can use 010 it is exactly equal to 8 according to Octal literals.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12149
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by RACHIT JAIN:
I know in place of 08 I can take as 8, but that will not work in my case.

Can you tell us WHY that won't work in your case? the number '08' is exactly the same as the number '8' (mathematically speaking - in java, the two literals have a different meaning). We can't see why it would make any difference which you use when building your hashmap, so you have to give us an explanation if we are to give you any more advice.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This thread is from last July, so I doubt we'll get any new clarification from the original poster.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49472
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mike Simmons:
This thread is from last July . . .


I hadn't noticed that. Welcome to JavaRanch ( ) Krishna Manohar, but please have a look at this FAQ
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic