Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1196 :

Posted: Tue Sep 17, 2013 4:56 am
by TheSarjo
Hello!
in explanation of this exercise, there is this statement:
2. The switch variable must be big enough to hold all the case constants.
So, if switch variable is of type char, the no case constant can be greater than 65535 because char's range is from 0 to 65535.
I don't understand what is a "no case constant".
Could someone do an example?
Sorry if the question is probably dumb.
Thank you very much!

Re: About Question enthuware.ocajp.i.v7.2.1196 :

Posted: Tue Sep 17, 2013 6:19 am
by admin
It is a typo, it should say, "...theN no case constant...". Here is an example:

Code: Select all

switch(x){

case 10: ...
case 20: ...

}
10 and 20 are the constants mentioned above. You cannot have variables here.
If x is declared of type byte, then you cannot have case 255: because 255 is too big for a byte.
HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.1196 :

Posted: Wed Sep 18, 2013 9:00 am
by TheSarjo
Ahhhh :-) :oops:
sorry, for a moment i was lost..
thank you!

Re: About Question enthuware.ocajp.i.v7.2.1196 :

Posted: Fri Nov 28, 2014 1:39 am
by gparLondon
Now, do we have to remember the range of all primitive type for the exam?

Re: About Question enthuware.ocajp.i.v7.2.1196 :

Posted: Fri Nov 28, 2014 1:44 am
by admin
Not for all but at least for byte.