public class VariousMethods {
private VariousMethods () {
}
public static void reverseArray (int[] array) {
int temp;
int length = array.length;
for (int i = 0; i < length; i++) {
temp = array[length - 1];
array[i] = temp;
--length;
}
for (int j = 0; j < length; j++) {
System.out.print (array[j] + " ");
}
System.out.println ("");
}
public static void main (String[] args) {
int[] array1 = {1, 2, 3};
int[] array2 = {6, 7, 8, 9, 6, 5};
int[] array3 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
VariousMethods.reverseArray(array1);
VariousMethods.reverseArray(array2);
VariousMethods.reverseArray(array3);
}
}
/*
OUTPUT:
3
5 6 9
0 1 2 3 4
*/
However, the code only prints half of the reversed array and I am unsure why. Any explanation as to why this is happening is very appreciated. Thanks!

New Topic/Question
Reply




MultiQuote




|