Ask Question

Assume the method doSomething has been defined as follows: public static void doSomething (int[] values, int p1, int p2) { int temp = values[p1]; values[p1] = values[p2]; values[p2] = temp; } What does the method do? Group of answer choices

a. It inserts a new value into the array values.

b. It swaps the integer values stored in positions p1 and p2 of the array values.

c. It copies the integer array values to a new array.

d. It moves each element of the array values to a higher index position.

+4
Answers (1)
  1. 29 November, 16:59
    0
    The answer to this question is option "b".

    Explanation:

    In the method definition, we perform swapping. To perform swapping we define a variable "temp" that swap values of variable p1 and p2 and store in array that is "values". and other options are not correct that can be defined as:

    In option a, It does not insert any new value in array because we do not pass any value in function. In option c, The function does not copy and assign a value in a new array because in this function we not assign any new array. In option d, It is incorrect because it can not move an element into high index position.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Assume the method doSomething has been defined as follows: public static void doSomething (int[] values, int p1, int p2) { int temp = ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers