Answer:
Explanation:
The following code is written in Java and it asks the user for the size of the array. Then it randomly populates the array and prints it. Next, it rotates all the elements to the right by 1 and prints the new rotated array.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
class Brainly {
public static void main(String[] args) {
Random r = new Random();
Scanner in = new Scanner(System.in);
System.out.println("Enter Size of the Array: ");
int arraySize = in.nextInt();
ArrayList<Integer> myList = new ArrayList<>();
for (int x = 0; x < arraySize; x++) {
myList.add(r.nextInt(15));
}
System.out.println("List Before Rotation : " + Arrays.toString(myList.toArray()));
for (int i = 0; i < 1; i++) {
int temp = myList.get(myList.size()-1);
for (int j = myList.size()-1; j > 0; j--) {
myList.set(j, myList.get(j - 1));
}
myList.set(0, temp);
}
System.out.println("List After Rotation : " + Arrays.toString(myList.toArray()));
}
}