The code print the original array twice. The code works just fine under main methods, but it fail when it runs under reverseArray method
package en.codegym.task.pro.task06.task0605;
/*
Correct order
*/
public class Solution {
public static void main(String[] args) {
int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
printArray(array);
Solution.reverseArray(array);
printArray(array);
}
public static void reverseArray(int[] array) {
int []temp = new int [array.length];
int j = array.length-1;
for(int i =0; i<temp.length; i++){
temp[i] = array[j];
j--;
}
array = temp;
}
public static void printArray(int[] array) {
for (int i : array) {
System.out.print(i + ", ");
}
System.out.println();
}
}