aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Chisolm mock exam query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Chisolm mock exam query" Watch "Chisolm mock exam query" New topic
Author

Chisolm mock exam query

ketki kalkar
Ranch Hand

Joined: May 09, 2007
Posts: 36
hi,

Thankyou chandra for helping me with the study process and other queries as well.I have one question regarding the chisolm mock exam.See the code below:
class JMM113 {
public static void main (String[] args) {
int i = 0, j = 0, k = 0;
do while (i++ < 3)
System.out.print(k++);
while (j++ < 3);
}}

What is the result of attempting to compile and run the program?

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

The answer is Prints: 012
Can you please explain?
Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
HI,
public static void main (String[] args) {
int i = 0, j = 0, k = 0;
do while (i++ < 3)
System.out.print(k++);
while (j++ < 3);
}}


i,j,k will be post increment so your are getting that output.


Regards
NIK
SCKP 1.5
John Stone
Ranch Hand

Joined: May 04, 2007
Posts: 332
You can find helpful, if you debug this code using some IDE (netbeans, eclipse), so you can trace every line and see how each variable is changing.
rajesh baba
Greenhorn

Joined: May 19, 2007
Posts: 25
class test
{
public static void main (String[] args)
{
int i = 0, j = 0, k = 0;
do
{
while (i++ < 3 )
{
System.out.print(k++);
}
} while (j++ < 3);
}
}

its a while loop inside do while loop so the code inside do while will be executed once so inner while loop prints 012 and do while runs three times but the value of i became 3 in so inner while condition fails so even though outer do while executes three time inner while loop executes only once so
output is:012
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Chisolm mock exam query
 
Similar Threads
Could some one explain the follwoing..
loops
increment operator
Dan's Mock FLow Question
loops