Hello there.
I have a working method here, called rotateRight() that takes an array and shifts all the elements to the right, except the last one that is placed at the start
I have debugged the method, and the method works fine. However the changes are not being reflected in main(). What should I change to fix that?
Thank you for your time.
B.
import java.util.*;
public class TestRotateRight {
public static void main(String[] args) {
int[] list = {3, 8, 19, 7};
rotateRight(list);
System.out.println(Arrays.toString(list)); // [7, 3, 8, 19]
rotateRight(list);
rotateRight(list);
System.out.println(Arrays.toString(list)); // [8, 19, 7, 3]
rotateRight(list);
System.out.println(Arrays.toString(list)); // [3, 8, 19, 7]
rotateRight(list);
rotateRight(list);
rotateRight(list);
System.out.println(Arrays.toString(list)); // [8, 19, 7, 3]
rotateRight(list);
rotateRight(list);
rotateRight(list);
rotateRight(list);
System.out.println(Arrays.toString(list)); // [8, 19, 7, 3]
}
public static void rotateRight(int[] array){
int temp = array[array.length-1];
int[] arrayTemp = new int[array.length];
arrayTemp[0] = temp;
for (int i = 0; i <= array.length - 2; i++) {
arrayTemp[i+1] = array[i];
}
array = arrayTemp;
}
}