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

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!