Page 1 of 1

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

Posted: Fri Jan 02, 2015 4:20 pm
by disznoperzselo
I miss an option here. I know some folks would be glad to choose 'infinitely many` if it were given :mrgreen: .

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

Posted: Tue Jan 27, 2015 6:28 am
by gparLondon
This is bit diversion to the actual question and the options,

What if the options include, infinite loop, one should go for which one, between(infinite loop and none of the above) according to you.

Thanks,
GPAR

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

Posted: Tue Jan 27, 2015 9:23 pm
by admin
None of the above, because it is not an infinite loop.

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

Posted: Tue Feb 07, 2017 3:54 pm
by jamesmccreary
I believe this is a bit question, yes? The book I used to study did not mention bits at all anywhere, yet I have seen 3+ questions in 2 practice tests that cover this. The book states that it covers everything you need to know.

So for the real exam, should I learn how bits work and what values correspond to what? I'm awed when others start giving answers and discuss using bits, for my non-programming background self :)

Thank you!

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

Posted: Tue Feb 07, 2017 10:08 pm
by admin
No, it is not really a bit question. It is a question that tests you on your knowledge of the values that an int can take. The actual MIN value or MAX value is not important here but just the fact that any int variable cannot keep incrementing or decrementing for ever. It will roll over at one point.

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

Posted: Thu Apr 15, 2021 2:08 pm
by Sieusc
Just a note, this question is marked as Very Tough. Don't know if this was the intent but imo an easy question

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

Posted: Mon May 24, 2021 4:55 pm
by meekaL
How do we know that loop keeps iterating...?

The explanation says "A do-while loop is always executed at least once. So in the first iteration, x is decremented and becomes 9. Now the while condition is tested, which returns true because 9 is less than 10. So the loop is executed again with x = 9. In the loop, x is decremented to 8 and the condition is tested again, which again returns true because 8 is less than 10."

HOWEVER, this does not make sense to me, they just say the loop is executed again after x is decremented. How do we know this from the code fragment? i put the code fragment below for reference...

int x = 10;
do{
x--;
System.out.println(x); // 1
}while(x<10);

There is nothing that indicates to me that the "do" block runs more than once because the "while" block is not there/ doesn't exist..... or am I missing something? :oops:

The only explanation I can think of is I am missing the idea of a do-while loop completely. Does the "do" block execute when the "while condition is true without regard to the "while" 's block or does it execute only when referred to from within the "while" block (ie Recursion type of effect) ...?

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

Posted: Mon May 24, 2021 8:11 pm
by admin
In the do-while construct, the block of code following do, is the while's block. There is no other while block. This is a bit different from the while loop construct where the while's block follows the while keyword.
So yes, in the case of a -do-while loop, if the while's condition is true, then the block of code written above is executed again.

Please go through this trail to get the basics of the while and do-while loops: https://docs.oracle.com/javase/tutorial ... while.html
Or go through any good Java book.