+ 1

Using arrays display the numbers in reverse order.

how can I solve it

28th Jul 2016, 2:48 AM
keerthana
4 Answers
+ 3
Actually, I would use: for (int i = array.length - 1; i >= 0; i--) { Console.WriteLine(array[i]); } Robert's code will generate an error as array.length is 5 and there is no element with index 5.The 1st element has index 0, second has index 1 and so on. In general, last element in an array has index array.length - 1
28th Jul 2016, 5:04 PM
Tomek Cymes
Tomek Cymes - avatar
+ 2
you should do it with a for loop int[] array = new int {1,2,3,4,5}; for(int i = array.length; i > 0; i--) { Console.WriteLine(array[i]); }
28th Jul 2016, 4:21 AM
Róbert Pécz
Róbert Pécz - avatar
+ 2
thank you
28th Jul 2016, 7:12 AM
keerthana
+ 1
yep miss that one. Not reversing a lot of array tó be honest
28th Jul 2016, 5:13 PM
Róbert Pécz
Róbert Pécz - avatar