Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

• Write a method with method header int[] getLargestAndSmallest(int[] list, int

ID: 3629945 • Letter: #

Question

• Write a method with method header int[] getLargestAndSmallest(int[] list, int size) which returns a 2-element int array. list is an incoming array, & size is its size <= list.length.
This method should declare a two-element array, call it output, that it will return at the end; the first element of this new array (output[0]) will be the largest value in the input array list, and the second element (output[1]) will be the smallest value in list.
Declare two local int variables, largest and smallest; initialize largest to Intger.MIN_VALUE and smallest to Integer.MAX_VALUE. You’ll use these as temporary variables in the following loop.
Use a for loop and if statements to go through the list array from index 0 to size-1 to find its largest and smallest elements, and put them into largest and smallest.
At the end of the loop, install the values you put into largest and smallest into the output 2-element array in that order and return that array as follows: return output;.

Explanation / Answer

public in[]getLargestAndSmallest(int[] list, int size){ int[] out = new int[2]; int Integer.MIN_VALUE = list.[0]; int Integer.MAX_VALUE = list.[0]; for (int i = 0; i