Code:
public static int[] reverse(int [] arr){
Int [] newArr = new int[arr.length];
for (int k = 0; k<arr.length;k++){
/*Missing statement */
}
return newArr;
Answer:
Replace the comment with:
newArr[k] = arr[arr.length-k];
Step-by-step explanation:
Required
Complete the code
In the given code:
The first line of the given code defines the method
public static int[] reverse(int [] arr){
The next line declares array newArr withe same length as array arr
Int [] newArr = new int[arr.length];
The next line iterates through the elements of array arr
for (int k = 0; k<arr.length;k++){
The /* Missing statement */ is then replaced with:
newArr[k] = arr[arr.length-k];
The above statement gets the elements of array arr in reversed order.
This is so because, as the iteration iterates through array arr in ascending order, arr.length-k gets the element in reversed order