wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes case statements range??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "case statements range???" Watch "case statements range???" New topic
Author

case statements range???

venkatesh badrinathan
Ranch Hand

Joined: Aug 03, 2008
Posts: 77
"Case statements must have values within permissible range"
Can anybody explain the above statement please...


SCJP1.5
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Originally posted by venkatesh badrinathan:
"Case statements must have values within permissible range"
Can anybody explain the above statement please...


Thats self explanatory, In case statement when you switch on different values then they must be in a permissible range , like

if you switch statement takes an int as a parameter then , the case statement must be in a range -2 147 483 648 to 2 147 483 647.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
venkatesh badrinathan
Ranch Hand

Joined: Aug 03, 2008
Posts: 77
Thanks Sagar Rohankar, but still i have some issues.
i think switch case can accept only integer values, although we pass char, byte, short, enum it converts to an int value.. am i right??? please explain
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

yes you are right , in addition to this ;
what Java lang specification says :

Expression must be char, byte, short, int, Character, Byte, Short, Integer, or an enum type (�8.9), or a compile-time error occurs.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Originally posted by venkatesh badrinathan:
Thanks Sagar Rohankar, but still i have some issues.
i think switch case can accept only integer values, although we pass char, byte, short, enum it converts to an int value.. am i right??? please explain


This means that if you use a byte variable in switch, then all the values of the case labels must be within the range of byte.
Eg-

The second case label generates an error as the value 178 is not in the range of byte.


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: case statements range???