0
How to reverse an array without using another array
3 Respostas
+ 8
Collections.reverse() can do that job for you if you put your numbers in a Listof Integers.
List<Integer> list = Arrays.asList(1, 4, 9, 16, 9, 7, 4, 9, 11);
System.out.println(list);
Collections.reverse(list);
System.out.println(list);
0
A variable.
Save the first cell of the array in a temp.
take last cell content to the first one.
move temp to last cell.
repeat with second cell and cell before last and so on...
If array len is even, reach the middle.
if array len is not even, the middle cell does not move.
0
int[] array = {1,2,3};
ArrayUtils.reverse(array);