File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "strange switch behavior" Watch "strange switch behavior" New topic

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 L´┐Żubli, SCJP 1.4, CLP 5.0, SCWCD 1.4 (preparing)
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

"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?

wood burning stoves
subject: strange switch behavior