• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wrong answer in the JavaRanch Rule Round-up Game

 
Sergey Zakusov
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

javaranch_game2_135.png
[Thumbnail for javaranch_game2_135.png]
Question #135
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12149
31
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergey Zakusov wrote:Ok. You are right.
EFH usually is.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic