Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Complete the rotate method. It shifts all the values in the array one index to the left and the number that was at index zero
Complete the rotate method. It shifts all the values in the array one index to the left and the number that was at index zero is moved to the end of the array. For example, if the array is initially { 1, 2, 3 } then after the method the array will be { 2, 3, 1 }.
If the array length is less than 2, the method does not change the array.
public class Main { public static void main(String[] args) { int [] a { 3, 6, 2, 9 }; rotate( a ); for ( int num: a ) System.out.print( num + " "); // 6 2 9 3 System.out.println(); = int [] b = { 11, 55, 2, -12, -2000, 91 }; rotate( b ); for ( int num : b) System.out.print( num + "); // 55 2 -12 -2000 91 11 } public static void rotate( int [] a ) { }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