Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 2 (20 points) In this problem, we will implement two shifting methods that will shift the input array to the left/right by one index
Problem 2 (20 points) 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 array LeftShift that accepts an int array, and shift each element of the input array to the left by one index position. That is, the Oh element would become (arr.length- 1)th element, the 1' element would become the Oh 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 6 2 8 1 4 6 After left shifting, testarri is 7 5 9 6 2 8 1 4 63 Before left shifting, testArri is 7 59 28 1 4 6 3 After left shifting, testarri is 5 9 0 2 8 1 4 6 3 7 Before left shifting, testarri is 59 0 2 8 1 4 6 3 7 After left shifting, testArri is 2 0 2 8 1 4 6 3 7 5 b) Write a function named array RightShift 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 1* element would become the 200 element, the last element would become the Och element, etc. The function header would appear as public static void arrayRightShift (int[] inArr) Use the following sample int array, int[] test Arr2 = {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 9 4 5 1 2 6 9 8 3 7 Before right shifting, testarr2 is 9 4 5 1 2 6 9 8 3 7 After right shifting, testArr2 is 7 @ 4 5 1 2 6 9 8 3 Before right shifting, testArr2 is 7 6 4 5 1 2 69 83 After right shifting, testArr2 is 3 7 0 4 5 1 2 6 9 8
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