File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Ranch Office and the fly likes Wrong answer in the JavaRanch Rule Round-up Game Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » This Site » Ranch Office
Reply Bookmark "Wrong answer in the JavaRanch Rule Round-up Game" Watch "Wrong answer in the JavaRanch Rule Round-up Game" New topic
Author

Wrong answer in the JavaRanch Rule Round-up Game

Sergey Zakusov
Greenhorn

Joined: Jun 10, 2010
Posts: 3
Question #135 should be corrected.

Answer can be "false" because there is no information about break statement.
So the default statement will execute even a case value matches switch() argument, for example:




[Thumbnail for javaranch_game2_135.png]

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

From where you get this question. This is not the right forum to post it. What is the complete question? Because if no match found then also default case will be executed.


Life is easy because we write the source code.....
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24045
    
  13

Hi,

Welcome to JavaRanch, and thanks for the feedback!

I believe the answer is correct as it stands. It says that the default clause will execute if no case matches, and that's absolutely true. It's possible that the default will execute if a case matches, also -- but that doesn't make the original statement false. If the question had said "True or false: the default clause will only execute if no case matches", then I would agree with you, but it does not say that.


[Jess in Action][AskingGoodQuestions]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24045
    
  13

Pramod P Deore wrote:This is not the right forum to post it.


As he says in the subject line, it's from the JavaRanch Rules Roundup Game, and this is absolutely the right place to post this.
Sergey Zakusov
Greenhorn

Joined: Jun 10, 2010
Posts: 3
Pramod P Deore wrote:From where you get this question.

http://www.javaranch.com/game/game2.jsp

Pramod P Deore wrote:This is not the right forum to post it.

Paul Wheaton said me to post it here.

Pramod P Deore wrote:What is the complete question? Because if no match found then also default case will be executed.

It's not a question. It's just a proposal.
Sergey Zakusov
Greenhorn

Joined: Jun 10, 2010
Posts: 3
Ernest Friedman-Hill wrote:If the question had said "True or false: the default clause will only execute if no case matches", then I would agree with you, but it does not say that.

Ok. You are right.
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Hi, Sergey , Actually I don't know about the JavaRanch Rule Round-up Game therefore I had asked that questions. but now I got my mistake. Thanks I will also check JavaRanch Rule Round-up Game.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9940
    
    6

Sergey Zakusov wrote:Ok. You are right.
EFH usually is.


Never ascribe to malice that which can be adequately explained by stupidity.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: Wrong answer in the JavaRanch Rule Round-up Game
 
Similar Threads
default statement
Something is missing in my Switch method
switch doubt..
switch case
What is this?