public class TestArray {
public static void main(String[] args) {
int[] ar = {1,2,3,4,5,6,7,8,9};
shiftRight(ar);
for (int i = 0; i <
The problem is that you create a local variable temp array, and you set ar=temp. You need to actually modify the contents of ar, rather than creating a new local array and pointing your copied ar variable to temp
Try something like this.
public static void reverseArray(int[] ar) {
int[] temp = new int[ar.length];
System.arraycopy( ar, 0, temp, 0, ar.length );
for (int i = 0, j = temp.length - 1; i < ar.length; i++, j--) {
ar[i] = temp[j];
}
for (int i = 0; i < ar.length; i++) {
System.out.print(ar[i]);
}
// prints: 876543219
System.out.println();
}