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 increment operator 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 "increment operator" Watch "increment operator" New topic

increment operator

ketki kalkar
Ranch Hand

Joined: May 09, 2007
Posts: 36

Following is a sample of code given in chisolm mock exam.

class JMM117 {
public static void main (String[] args) {
int i = 0, j = 9;
do {
if (j-- < i++) {break;}
} while (i < 5);
System.out.print(i + "," + j);

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

a. Prints: 5,4
b. Prints: 6,3
c. Prints: 6,6
d. Prints: 7,2
e. Run-time error
f. Compile-time error
g. None of the above

It Prints: 6,6
Can Anyone please explain?

Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1710
Hi Ketki,

Put System.out.print("i = " + i + " j = " + j); inside the loop, to better
understand the things happening in the loop.


I agree. Here's the link:
subject: increment operator
It's not a secret anymore!