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

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

Moderator: admin

Post Reply
lucvandewall
Posts: 2
Joined: Fri Apr 24, 2015 9:04 am
Contact:

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

Post by lucvandewall »

I answered "It fails to compile" as it doesn't has a main in the code.
Obviously that is also not true.. but without a main it also cannot print something.

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

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

Post by admin »

lucvandewall wrote:I answered "It fails to compile" as it doesn't has a main in the code.
Obviously that is also not true.. but without a main it also cannot print something.
No, that is ok. This is as per the pattern of questions in the real exam. Many questions do not have complete compilable code. They just just show you the relevant code snippet. You have to assume that the given code is wrapped in an appropriate but irrelevant context of a class and a main method.

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

rch1984@gmail.com
Posts: 1
Joined: Thu Feb 25, 2016 9:51 am
Contact:

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

Post by rch1984@gmail.com »

I am struggling to grasp the quessitons when there is a While loop running inside a foreach loop. Could someone point out some ways to maybe write it out or maybe the way you read it?

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

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

Post by admin »

rch1984@gmail.com wrote:I am struggling to grasp the quessitons when there is a While loop running inside a foreach loop. Could someone point out some ways to maybe write it out or maybe the way you read it?
The way to handle such type of questions is to use a pen and a paper (you will be provided with these in the exam) and note down the values of each variable at each iteration of outer and inner loop. Like this:

Outer for Iteration 1:
innerCounter=0, dataElement = x
Inner while Iteration 1: 0<3 so execute while body
print dataElement, innerCounter =>x, 0
increment innerCounter to 1
Inner while Iteration 2:1<3 so execute while body
print dataElement, innerCounter =>x, 1
increment innerCounter to 2
Inner while Iteration 3:2<3 so execute while body
print dataElement, innerCounter =>x, 2
increment innerCounter to 3
Inner while Iteration 4: 3 !<3 so stop the while loop
Outer for Iteration 2:
innerCounter=1, dataElement = y
...
so on...


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

ramon.carrascom
Posts: 19
Joined: Sun Aug 27, 2017 12:35 pm
Contact:

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

Post by ramon.carrascom »

Why doesn't the second iteration of the for loop raise an exception when it reaches the int innerCount line? AFAIK, int already is declared in the first iteration. Doesn't it try to redeclare i? Does "innerCount" fall out of scope in each iteration? Thanks

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

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

Post by admin »

Yes, the scope of innerCount is only withing an iteration of the for loop. Each iteration effectively creates a new variable innerCount. The one created in the previous iteration is gone with that iteration.

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

Meghana
Posts: 29
Joined: Sun Feb 11, 2018 3:13 am
Contact:

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

Post by Meghana »

How come innerCount is incremented to 0, 1 , 2? Shouldn't the scope of innerCount remain within the while loop (as it does for for loop)? So, each time we come out of the while loop, how come innerCount is incremented?

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

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

Post by admin »

innerCounter is declared outside the while loop but inside the for loop.
If you like our products and services, please help us by posting your review here.

Meghana
Posts: 29
Joined: Sun Feb 11, 2018 3:13 am
Contact:

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

Post by Meghana »

Ohww! I din look at the braces! Thank you. :D

Post Reply

Who is online

Users browsing this forum: No registered users and 93 guests