Question: In this problem, we will implement two shifting methods that will shift the input array to the left/right by one index position. a) Write a


In this problem, we will implement two shifting methods that will shift the input array to the left/right by one index position. a) Write a function named arrayLeftShift that accepts an int array, and shift each element of the input array to the left by one index position. That is, the oth element would become (arr.length- 1)th element, the 1st element would become the oth element, the 2nd element would become the first element, etc. The function header would appear as public static void arrayLeftShift (int[] inArr) Use the following sample int array, int[] testArr1 = {3, 7, 5, 9, 0, 2, 8, 1, 4, 6}; and code up a loop that shifts the input array 3 times in the main method. For each loop, please print the results. A sample output is given as follows Let's left shift the testarri 3 times: Before left shifting, testarri is 3 7 5 9 0 2 8 1 4 6 After left shifting, testarri is 7 5 9 0 2 8 1 4 6 3 Before left shifting, testarri is 7 5 9 0 2 8 1 4 6 3 After left shifting, testarri is 5 9 0 2 8 1 4 6 37 Before left shifting, testarri is 59 0 2 8 1 4 6 37 After left shifting, testarri is 2 O 2 8 1 4 6 3 7 5 b) Write a function named arrayRightShift that accepts an int array, and shift each element of the input array to the right by one index position. That is, the oth element would become the 1st element, the 1st element would become the 2nd element, the last element would become the oth element, etc. The function header would appear as public static void array RightShift (int[] inArr) Use the following sample int array, int[] testArr2 = {4, 5, 1, 2, 6, 9, 8, 3, 7, 0}; and code up a loop that shifts the input array 3 times in the main method. For each loop, please print the results. A sample output is given as follows Let's right shift the testarr2 3 times: Before right shifting, testarr2 is 4 5 1 2 6 9 8 3 7 0 After right shifting, testarr2 is 0 4 5 1 2 6 9 8 3 7 Before right shifting, testarr2 is 0 4 5 1 2 6 9 8 3 7 After right shifting, testarre is 7 0 4 5 1 2 6 9 8 3 Before right shifting, testarr2 is 7 0 4 5 1 2 6 9 8 3 After right shifting, testarre is 3 7 0 4 5 1 2 6 9 8
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
