aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes mock question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "mock question" Watch "mock question" New topic
Author

mock question

pritam kamkar
Greenhorn

Joined: Jul 23, 2008
Posts: 3

it says that the output is 21 but i did not understand the logic behind the output being 21
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Welcome to JavaRanch.

The question is moot, as the code doesn't compile. Also, please QuoteYourSources.


Ping & DNS - updated with new look and Ping home screen widget
KP Embanath
Greenhorn

Joined: Jul 22, 2008
Posts: 1
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

Joined: Jul 05, 2008
Posts: 141
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.



SCJP Java 6 (98%) - Story, SCJA (88%) - Story
Milan Sutaria
Ranch Hand

Joined: Jul 10, 2008
Posts: 118
how about using the simpliest debugging technique... inserting the System.out.println statements in switch and/or while


SCJP 6 83%
Working on SCWCD/OCPJWCD
jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
Here ordinal() returns 4 , how does the ordinal() method actually work

Ravinderjit Singh
Ranch Hand

Joined: Jan 13, 2010
Posts: 68
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

Joined: Mar 22, 2010
Posts: 308

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


SCJP6, SCWCD5, OCP-JBCD5, OCE-JWSD6 OCE-JPAD6 , OCM-JEA5 1,OCM-JEA5 2,3 - Brainbench certifications: J2EE, Java2, Java2-NonGUI, JSP, SQL2000 Admin, SQL2000 Programming , Brainbench certified Java Programmer, Computer Programmer, Web Developer, Database Administrator
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mock question
 
Similar Threads
Switch with Enum (Was: Explain the output)
please explain - code output
Enums
Whats the output...
Problem with a mock exam question