In this exercise, the goal is to write program called ArrayRotate that takes a series of integers from the command-line, stores them in an array nums, then copies them into a new array copy so that the values are rotated left by one. Here’s an example of what should happen when the elements of copy are printed out to the terminal:
: java ArrayRotate 1 2 3 4 5 2 3 4 5 1
In other words, the \( i^{th} \) element of copy is the \( i+1^{th} \) element of nums, except that the last element of copy is the first element of nums.
After creating the two arrays, nums and copy, you should write three for loops:
- The first loop will read in arguments from the command-line and store them as integers in nums.
- The second loop will copy elements from nums to copy in the rotated fashion described above.
- The third loop will iterate through copy, printing out its elements, each of which should be followed by a single space. The whole series of elements should be terminated by a newline.
An automated test has been created for this exercise: ArrayRotateTest.java.