Question: JAVA ARRAY PROBLEMS ASSIGMENTS HELP PLEASE.///////////// This week, it is time to practice arrays so that our methods can process millions of items of data,
JAVA ARRAY PROBLEMS ASSIGMENTS HELP PLEASE./////////////
This week, it is time to practice arrays so that our methods can process millions of items of data, giving our loops and conditions something useful to do. Create a class ArrayProblems and write the following array methods in it. Again, you must use the JUnit test class TestArrayProblems.java to test out your methods. (tester is on the bottom of the page via pastebin) 1.int[] everyOther(int[] a) that creates and returns an array that contains the elements from the even-numbered positions of the array a, that is, the elements a[0], a[2], a[4],... Make sure to compute the length of the result array exactly right so that there is no extra element in the end. (You need to consider odd and even lengths of a separately. The remainder operator % might come handy here.) 2.int countInversions(int[] a) that counts how many inversions there exist inside the array a. An inversion is a pair of indices (i, j) to the array so that i < j and a[i] > a[j]. Use two nested for-loops to loop through all possible pairs of array indices. (In the analysis of sorting algorithms, the inversion count is an important measure of how out of order the elements of an array are compared to a sorted array that has an inversion count of zero.) 3.void squeezeLeft(int[] a) that modifies the contents of its parameter array a by moving all its nonzero elements to the left as far as it can, writing over the zero elements that precede them. For example, if called with the parameter array {0, 1, 0, 0, 3, -2, 0, 7}, the contents of this array after the call would be {1, 3, -2, 7, 0, 0, 0, 0}. (For an extra challenge, you can try make your method work in place so that it doesnt create another array to use as temporary workspace. For an even harder challenge for the truly hardcore among you, make your method work in one pass through the array.) 4.int[] runDecode(int[] a) that takes an array that consists of a series of element values followed by the lengths of the run of those elements, listed in alternating locations. This method creates and returns a new array that contains these elements, each element repeated the number of times given by its run length. For example, when called with the array {3, 8, 1, -7, 0, 42, 4, -3} (read this out loud as three eights, one minus seven, zero forty-twos, and four minus threes), your method would create and return the array {8, 8, 8, -7, -3, -3, -3, -3}. Again, make sure that the array returned by your method has the exact right length. (You can assume that the length of the parameter array is even. A run length can never be negative, although it can be zero. As a possibly tricky edge case, the result array could even be empty, if each run has zero length!) IMPORTANT NOTE, it has to complie and run with the tester program which is http://pastebin.com/uQDhyTgk
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
