Question: IN JAVA Write a method that is passed an array, x, of doubles and an integer rotation amount, n. The method creates a new array

IN JAVA Write a method that is passed an array, x, of doubles and an integer rotation amount, n. The method creates a new array with the items of x moved forward by n positions. Elements that are rotated off the array will appear at the end. For example, suppose x contains the following items in sequence:

1 2 3 4 5 6 7

After rotating by 3, the elements in the new array will appear in this sequence:

4 5 6 7 1 2 3

Array x should be left unchanged by this method. Use the following code to help you get started.

public class practiceTextBook
{
 public static void main(String[] args)
 {
 double[] x = {8, 4, 5, 21, 7, 9, 18, 2, 100};
 System.out.println("Before rotation: ==============================");
 for (int i = 0; i < x.length; i++)
 {
 System.out.println("x[" + i + "]: " + x[i]);
 }
 x = rotate(x, 3);
 System.out.println("After rotation: =============================="); 
 for (int i = 0; i < x.length; i++)
 {
 System.out.println("x[" + i + "]: " + x[i]);
 } 
 }
 
 // Your method goes here.
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!