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

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

Moderator: admin

Post Reply
jbilkes
Posts: 21
Joined: Tue Sep 09, 2014 3:28 pm
Contact:

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

Post by jbilkes »

Hi all,

I'm new to this but quite surprised noone started a topic about this question...

My point is the following:

I can see why the 2 if loops are just for fun, very funny :P
But how can it NOT print '1' ?

the println does simply print out every 'i' sp why not the first element of the arraylist?

Is it a trick question and is the answer: "Yes, we didnt say it didnt print 1 also! Whoahahaha"

that would be somewhat hilarious and not quite intended to get the student to actually grasp more of the study material, and that is a comment directed to Oracle if they actually included such a mind-dumbing && energy-wasting 'trap'

But I guess I should feel stupid and there is a simple explanation hahah!

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

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

Post by admin »

The question wants you to write the code so that it doesn't print 1 but only 2345. Both the correct options put a continue in the first if i.e.
if (i < 2) {
continue;
}
Therefore, when i is 1, the print statement will not be executed. That is why it will not print 1.
If you like our products and services, please help us by posting your review here.

jbilkes
Posts: 21
Joined: Tue Sep 09, 2014 3:28 pm
Contact:

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

Post by jbilkes »

ok i get it, now i understand the diff between break and continue better, excellent question. Thanx

strauberry
Posts: 4
Joined: Wed Nov 19, 2014 3:22 am
Contact:

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

Post by strauberry »

I would like to add another question: why do I need the "continue" in code2? After the if-block no further code is executed, so for me there is no semantic difference between having an empty code2 or putting "continue" for code2. Thank you!

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

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

Post by admin »

strauberry wrote:I would like to add another question: why do I need the "continue" in code2? After the if-block no further code is executed, so for me there is no semantic difference between having an empty code2 or putting "continue" for code2. Thank you!
There is no need for the second continue. It is there just to confuse you :) The goal of the question is to make sure you understand how the continue works.

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

strauberry
Posts: 4
Joined: Wed Nov 19, 2014 3:22 am
Contact:

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

Post by strauberry »

Hi Paul, thank you for your answer! I assuemd something like that :-) But not both alternatives are correct... is there a reason for this, as well?

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

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

Post by admin »

strauberry wrote:Hi Paul, thank you for your answer! I assuemd something like that :-) But not both alternatives are correct... is there a reason for this, as well?
Both are correct. Why do you think the second one is wrong?
If you like our products and services, please help us by posting your review here.

strauberry
Posts: 4
Joined: Wed Nov 19, 2014 3:22 am
Contact:

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

Post by strauberry »

In general, the second answer is not wrong, but the software doesn't mark it as a correct answer ^^

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

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

Post by admin »

It does. I see both options 2 and 3 as marked correct.
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 88 guests