About Question enthuware.ocajp.i.v7.2.848 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

About Question enthuware.ocajp.i.v7.2.848 :

Post by ETS User »

Question 15 of 45 in the very easy test.

I am just a bit confused. The answer says to decrement the value k and then compare.

As k = 2, if you decrement the value of k, does it not become 1 and then you compare.

I just dont understand why the answer is not just 1. I do not get why 2 is in the answer if we decremented k before comparison.

Sorry I am probably missing something very basic here.

admin
Site Admin
Posts: 10066
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.848 :

Post by admin »

You are thinking correctly. But you are missing one point that the print statement is present even before the while condition. So, first you enter the do block, print k (which is 2 at this point), and then evaluated the while condition. As a part of evaluating the while condition, you first decrement k (because of --k), so now k becomes 1. since 1 is > 0, you go back to the do block. print k (which is 1), and then evaluated the while condition....and so on.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Guest

Re: About Question enthuware.ocajp.i.v7.2.848 :

Post by Guest »

That's great, thanks very much Paul.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 234 guests