About Question enthuware.ocajp.i.v7.2.1386 :
Moderator: admin
-
- Posts: 21
- Joined: Tue Sep 09, 2014 3:28 pm
- Contact:
About Question enthuware.ocajp.i.v7.2.1386 :
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
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!
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
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!
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1386 :
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.
Therefore, when i is 1, the print statement will not be executed. That is why it will not print 1.if (i < 2) {
continue;
}
If you like our products and services, please help us by posting your review here.
-
- Posts: 21
- Joined: Tue Sep 09, 2014 3:28 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1386 :
ok i get it, now i understand the diff between break and continue better, excellent question. Thanx
-
- Posts: 4
- Joined: Wed Nov 19, 2014 3:22 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1386 :
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!
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1386 :
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.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!
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Wed Nov 19, 2014 3:22 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1386 :
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?
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1386 :
Both are correct. Why do you think the second one is wrong?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?
If you like our products and services, please help us by posting your review here.
-
- Posts: 4
- Joined: Wed Nov 19, 2014 3:22 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1386 :
In general, the second answer is not wrong, but the software doesn't mark it as a correct answer ^^
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1386 :
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.
Who is online
Users browsing this forum: No registered users and 88 guests