Page 1 of 1

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

Posted: Sat Mar 01, 2014 11:34 pm
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)

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

Posted: Sun Mar 02, 2014 12:41 am
by admin
Yes, you will see some questions like this where you have to work out the values.

HTH,
Paul.

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

Posted: Sat Jan 30, 2016 9:55 pm
by chronix
This is labeled "easy"?? An easier one like this is labeled "tough".

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

Posted: Wed Oct 05, 2016 1:12 pm
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.

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

Posted: Wed Oct 05, 2016 9:08 pm
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.

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

Posted: Sat Dec 24, 2016 9:46 pm
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!

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

Posted: Sun Dec 25, 2016 8:40 am
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.

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

Posted: Sun Apr 23, 2017 3:41 am
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

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

Posted: Sun Apr 23, 2017 4:58 am
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);