Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java round-up game #223

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I think the answer to the following question is wrong (well...
perhaps it's just because of the real odd wording). Could
you please verify?
---------------------------------------------------------------
(#223)TRUE of FALSE:
in a switch statement, the argument to the case label
(case: argument) can be any variable which can fit
within an int.
Answer: FALSE
The case argument must be either an int literal, or an
int-compatible variable which is a constant (i.e. static final).
---------------------------------------------------------------
The question asks if the argument can be a variable,
"which can fit within an int". This is definitely true!
It does not ask, if it needs to be a VARIABLE (or if it can
be something else like an int literal or constant).
So in my opinion this either needs to have the answer changed
or the word "variable" must be stressed in the question in order
to set things right.
Anyway... thanks for this really entertaining game ;)
Daniel
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(#223)TRUE of FALSE:
In a switch statement, the argument to the case label (case: argument) can be any variable which can fit within an int.
Answer: FALSE
The case argument must be either an int literal, or an int-compatible variable which is a constant (i.e. static final).

The key word is ANY variable. The argument to the case label must be a constant, either a static final (constant) variable or a literal. And, yes, the constant must also fit within an int (be int-compatible).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic