Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
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 The Software Craftsman this week in the Agile 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: 24189
    
  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
 
Have you tried LearnNowOnline? http://www.learnnowonline.com/
 
subject: strange switch behavior