my dog learned polymorphism*
The moose likes Beginning Java and the fly likes The Literal Octal 08 of type int is out of range Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The Literal Octal 08 of type int is out of range" Watch "The Literal Octal 08 of type int is out of range" New topic
Author

The Literal Octal 08 of type int is out of range

RACHIT JAIN
Greenhorn

Joined: Dec 26, 2005
Posts: 2
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

Joined: Apr 14, 2004
Posts: 10336


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 ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
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

Joined: Oct 27, 2005
Posts: 19651
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
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


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2991
    
    9
[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

Joined: Dec 30, 2008
Posts: 1
instead of 08, you can use 010 it is exactly equal to 8 according to Octal literals.


Thanks<br />Manohar
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11154
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2991
    
    9
This thread is from last July, so I doubt we'll get any new clarification from the original poster.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37962
    
  22
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The Literal Octal 08 of type int is out of range
 
Similar Threads
JSTL Get value from HashMap inside HashMap
Check one of the property of objects contains the given value
how to iterate a hashmap with key hashmap
put float into hashMap
ArrayList/HashMap - Sorting