Question
(Intro to Java help?) Write a static method named rotateRight that accepts an array of integers as a parameter and rotates the values in the
(Intro to Java help?)
Write a static method named rotateRight that accepts an array of integers as a parameter and rotates the values in the array to the right (i.e., forward in position) by one. Each element moves right by one, except the last element, which moves to the front. For example, if a variable named list refers to an array containing the values {3, 8, 19, 7}, the call of rotateRight(list) should modify it to store {7, 3, 8, 19}. A subsequent call of rotateRight(list) would leave the array as follows: {19, 7, 3, 8}.
Test your code with the following class:
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]
}
// your code goes here
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started