aspose file tools*
The moose likes Ranch Office and the fly likes java round-up game #223 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » This Site » Ranch Office
Bookmark "java round-up game #223" Watch "java round-up game #223" New topic
Author

java round-up game #223

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jul 22, 2000
Posts: 9043
    
  10
(#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).

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: java round-up game #223
 
Similar Threads
switch question in Roundup
question from Rules Roundp game
JavaRanch #223
somebody please explain me this
case label int-compatible variable