Clivant Yeo
My Personal Website
Why + 1? That looks like a mistake.Clivant Yeo wrote:. . .
Loop number of times equal to midpoint + 1.
Maintain two counters:
. . .
If first counter == second counter, break out of the loop.
sagar kumar nerella,
java certified professional
sagar kumar nerella wrote:hello
if i understood your problem correctly
you want some code demo showing the how to reverse the elements of an array using only one loop.
sagar kumar nerella,
java certified professional
... I shall delete the answer. There are better solutions, I believe.We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers
Campbell Ritchie wrote:You don’t need two counters. Only one.
If you use the correct values to count to, there is no need for the break. In fact, using break might introduce an out-by-one error, but I am not certain on that point. Depends how you use it.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie wrote:
Why + 1? That looks like a mistake.Clivant Yeo wrote:. . .
Loop number of times equal to midpoint + 1.
Maintain two counters:
. . .
If first counter == second counter, break out of the loop.
You don’t need two counters. Only one.
If you use the correct values to count to, there is no need for the break. In fact, using break might introduce an out-by-one error, but I am not certain on that point. Depends how you use it.
Clivant Yeo
My Personal Website
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |