This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes strange switch behavior Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "strange switch behavior" Watch "strange switch behavior" New topic
Author

strange switch behavior

Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
I have the following code:



My problem is in this line of code:

case 14 | 11 | 8 | 5 :

Why on earth do 11 and 5 bite eachother as duplicate labels? Take one out the other is happy and visa versa. Any idea why?

Marcus


Marcus L´┐Żubli, SCJP 1.4, CLP 5.0, SCWCD 1.4 (preparing)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

"15 | 13 | ..." is a single int. I know you mean "15 or 13 or ..." But what you're actually doing is bitwise logical operations.

The only way to write what you're trying to do looks like:



[Jess in Action][AskingGoodQuestions]
Marcus Laubli
Ranch Hand

Joined: Dec 24, 2004
Posts: 116
Thank you Ernest. That makes sense. Why didn't I thing of that?

Marcus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: strange switch behavior