get last number of random array when for loop loop i < 20

Posted 02 March 2012 - 09:30 AM

Hello,

When I run my program the first set of 20 numbers print on my console with one extra number (the last number of the sorted array).
The second set of numbers which is the last 20 numbers of the sorted array prints correctly. What am I doing wrong.

Replies To: get last number of random array when for loop loop i < 20

Re: get last number of random array when for loop loop i < 20

Posted 02 March 2012 - 09:54 AM

The last value of the array is printed because you do Console.WriteLine(" " + value[value.Length - 1]);. Note that you do that for both for-loops, so in the loop where you print the last 20 elements, the last one will be printed twice.

If you don't want this to happen, remove that line (or replace it with a call to WriteLine without arguments to get a linebreak).