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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.