Page 1 of 1

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

Posted: Tue Sep 09, 2014 3:44 pm
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!

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

Posted: Tue Sep 09, 2014 8:18 pm
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.

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

Posted: Wed Sep 10, 2014 2:27 am
by jbilkes
ok i get it, now i understand the diff between break and continue better, excellent question. Thanx

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

Posted: Wed Nov 19, 2014 4:55 am
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!

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

Posted: Wed Nov 19, 2014 10:18 am
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.

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

Posted: Wed Nov 19, 2014 10:35 am
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?

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

Posted: Wed Nov 19, 2014 10:40 am
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?

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

Posted: Thu Nov 20, 2014 4:18 am
by strauberry
In general, the second answer is not wrong, but the software doesn't mark it as a correct answer ^^

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

Posted: Thu Nov 20, 2014 5:58 am
by admin
It does. I see both options 2 and 3 as marked correct.