It's not a secret anymore!*
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "increment operator" Watch "increment operator" New topic
Author

increment operator

ketki kalkar
Ranch Hand

Joined: May 09, 2007
Posts: 36
hi,

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 {
i++;
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?

Thankyou
Chandra Bhatt
Ranch Hand

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

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



Thanks,


cmbhatt
 
Consider Paul's rocket mass heater.
 
subject: increment operator