File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes switch case valid? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "switch case valid?" Watch "switch case valid?" New topic
Author

switch case valid?

Timothy Leong
Ranch Hand

Joined: May 25, 2005
Posts: 55
hi, suppose I have option 1-6 that perform the same operation. can I use the following?



using case 1-6 instead?

Thanks
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Did you try to compile it?



SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Timothy Leong
Ranch Hand

Joined: May 25, 2005
Posts: 55
i tired compile it and run. The program still works.
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Maybe I din't understand you quesion.
You want this?

case -5:
break;
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
case 1-6
is the same as
case -5

so if you want 6 options
use
case 1:
case 2:
.
.
.
case 6:
....
break;
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
The syntax for Java's switch statement can be found in this section of the Java Language Specification. As David pointed out, 1-6 is a compile time expression with value -5.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: switch case valid?
 
Similar Threads
Switch Statements
Numeric value convert to word format
how do i loop not using a for statement?
Do while error, I'm going crazy
Switch Case