Question: 2. Add the following method to the class // This method receives a parameter giving the size of an array to // create, creates the

2. Add the following method to the class // This method receives a parameter giving the size of an array to // create, creates the array, fills the elements of the array with // random integer numbers within the range size/2 to +size/2, and // returns the reference (address) of the array. public static int[] makeArray(int size) { if (size < 1) return null; int[] a = new int[size]; for (int i=0; i

7. Add a static method to the class that receives an int array and nothing else. The method then returns a new array with elements containing a copy of the elements in the passed array, but in reverse order. For example, if the passed array contains the values 34 45 19 7 6 the returned array contains the values 6 7 19 45 34

8. In method main of class , add code to: (a) Prompt for and receive from the user the size of the initial array. (b) Call the method of (2), passing the size of the array and assigning the returned array to an array reference variable. (c) Call the methods of (3) and (4), passing the array returned from (2) in step (b). The return of each method called is output with an appropriate label. (d) Call the method of (5), passing the array returned from (2) in step (b). (e) Call the method of (6), passing the array returned from (2) in step (b). (f) Call the method of (7), passing the array returned from (2) in step (b) and assigning the returned array to an array reference variable. The contents of both arrays are then output with the values in matching indexes placed next to each other, one pair to a line with a comma between them. For example, if the two arrays contained the values 34 45 19 7 6 and 6 7 19 45 34 the output would look like 34,6 45,7 19,19 7,45 6,34

Example run:

Enter an integer greater than zero: 5

Array sum: 4

Array avg: 0

Sum of the array elements with an even index: 2

Odd numbers in the array: 2

-2 ,-2

-1,1

0, 0

1,-1

-2, -2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!