File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dan's Mock FLow 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 "Dan Watch "Dan New topic

Dan's Mock FLow Question

Vidyavathi saravanan
Ranch Hand

Joined: Sep 24, 2004
Posts: 34

Answer options:
a. Prints: 0001
b. Prints: 012
c. Prints: 012012
d. Prints: 012345
e. Prints: 001122
f. Prints: 1112
g. Prints: 111222
h. Prints: 121212
i. Run-time error
j. Compile-time error
k. None of the above

Answer is h. Could anyone please explain this to me?


(got rid of smiley in code portion)
[ October 16, 2004: Message edited by: Barry Gaunt ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Let's rewrite this a little:

This is entirely equivalent to the previous code. It maybe easier to analyze now.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Peixiao Lin

Joined: Oct 04, 2004
Posts: 28
do{}while(A) loop will iterate one more time than while(A){} loop. so in this case, the inside for loop will iterate 3 times. For each inside for loop iteration, the output is 12, so the final output is 121212
Vipin Das
Ranch Hand

Joined: Jul 05, 2004
Posts: 47
I agree. Here's the link:
subject: Dan's Mock FLow Question
It's not a secret anymore!