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

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

Moderator: admin

Post Reply
shining_dragon
Posts: 14
Joined: Sat Mar 01, 2014 9:12 am
Contact:

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

Post by shining_dragon »

I just want to know if the actual exam asks this kind of example? Because i think it may be time consuming to plot all values for count and sum (although they are easy)

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

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

Post by admin »

Yes, you will see some questions like this where you have to work out the values.

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

chronix
Posts: 5
Joined: Mon Jan 04, 2016 12:28 am
Contact:

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

Post by chronix »

This is labeled "easy"?? An easier one like this is labeled "tough".

elit3x
Posts: 7
Joined: Tue Oct 04, 2016 6:11 pm
Contact:

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

Post by elit3x »

Any time saving tips on how to approach these questions that require a lot of loop iterations?
Unfortunately i am not good at seeing the pattern, so i am stuck with writing down each iteration.

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

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

Post by admin »

You will need to work out the value of each variable for each iteration on paper. For beginners, this is the only way. Most people are able to run the iteration in their heads after a bit of experience.

But you should not worry. The questions in the exam do not have a lot of iterations. They are reasonable.

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

Deleted User 3513

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

Post by Deleted User 3513 »

I would like to know why the program continued to execute after the iteration count=10 and sum=37? After this loop iteration, count++ < 11 is the same as 11 < 11 which returns false and would exit the program because 11 is not strictly less than 11. Please help me understand. Thanks in advance!

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

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

Post by admin »

Observe that the while condition uses the post increment operator on count. You should read the count++<11 condition like this:
compare current value of count with 11, remember the result, increment count, and based on the result of the comparison proceed with the next iteration or exit the loop.

Therefore, when count is 10, the condition will return true, count will be incremented to 11 and then since the comparison is true, the loop will be continue once more. Now, count is 11, the condition will return false, count will be incremented to 12, and since the condition is false, the loop will terminate.

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

Chandu
Posts: 7
Joined: Thu Mar 30, 2017 7:15 am
Contact:

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

Post by Chandu »

What will the following code snippet print?

Code: Select all

int count = 0, sum = 0;
do{
       if(count % 3 == 0) continue;
       sum+=count;
}
while(count++ < 11);
System.out.println(sum);
//Please can u post iteration wise results in detail? m not able to analyse how to control flows properly.
Thanks
Last edited by admin on Sun Apr 23, 2017 4:56 am, edited 1 time in total.
Reason: Please enter code inside [code] [/code] tags

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

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

Post by admin »

Well, you should add some printlns to print the value of variables in each iteration like this and see what it prints.

Code: Select all

int count = 0, sum = 0;
do{
System.out.println("Outer iteration, count = "+count+" sum = "+sum);
       if(count % 3 == 0) continue;
       sum+=count;
}
while(count++ < 11);
System.out.println(sum);
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests