• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mock question

 
pritam kamkar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

it says that the output is 21 but i did not understand the logic behind the output being 21
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

The question is moot, as the code doesn't compile. Also, please QuoteYourSources.
 
KP Embanath
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pritam,

First of al there are so many compile errors in your code. We can only assign the enum value using dot operator some thing like r=Roman.L;

In the above example, just note the point that if the case block didn't have any "break" statement, then all the other case block coming below the current one will execute.

So we will get the output 21

Regards,
Krishna
 
Raphael Rabadan
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

that's a question of master exam, bonus one if i'm not wrong, and it works fine and show's 21, here is the code as it is:

Try to debug each iteration, if you do it and still can't get the answer, ask for help again.

 
Milan Sutaria
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how about using the simpliest debugging technique... inserting the System.out.println statements in switch and/or while
 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here ordinal() returns 4 , how does the ordinal() method actually work

 
Ravinderjit Singh
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each enum value in an enum class has an associated default value, starting with zero for the first value and incrementing by one for each additional value. This may be accessed with the ordinal() method.
 
Rajeev Rnair
Ranch Hand
Posts: 310
1
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pritam,

There are 4 Compile Errors in the code. Fixed all those, and the code is like the following in a Readable format. I have added a println() inside the do-while loop.


And the output is self explanatory . Consider the fall through in switch() {}


Hope this is clear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic