Question: Assume that the methods below (reverse and swap) are defined in the same class. Explain what is wrong and show all corrections that are needed.
Assume that the methods below (reverse and swap) are defined in the same class. Explain what is wrong and show all corrections that are needed.
/**
-
* reverse: reverses the elements of an array of integers.
-
* For example, if the array elements are 85, 99, 78, 100, then the array should be changed so
-
* that its elements are 100, 78, 99, 85. *
-
* @param a an array of integers
-
* @param len the number of elements in the array */
public void reverse(int[] a, int len) {
for (int i = 0; i < len; i++) this.swap(a[i], a[len i]);
}
/**
-
* swap: swaps (exchanges) two values. *
-
* @param x the first value
-
* @param y the second value */
public void swap(int x, int y) {
int temp; temp = x; x = y; y = temp;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
