Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

increment operator

 
ketki kalkar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ketki,

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



Thanks,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic