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

Write a method called exchangewhich takes two parameters: an int variable num, a

ID: 647916 • Letter: W

Question

Write a method called exchangewhich takes two parameters: an int variable num, and intArray, which is an array of type int.

The method returns an array of type int.

The method exchanges the value stored at position num (1 based, so that the first position for the user is at index 0 to the code) in the array intArray with the value at the first position in the array. It then returns this array.

Assume: 0 < num <= intArray.length

For example, on these inputs:

num = 3, intArray = {8, 6, 4, 5, 5}

The method would return this array:

5, 6, 4, 8, 5

Enter your answer below.

Explanation / Answer

int[] exchange(int[] intArray,int num)
{
   int temp=intArray[num];
   intArray[num]=intArray[0];
   intArray[0]=temp;

   return intArray;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote