Ask Question
8 March, 14:03

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.

+3
Answers (1)
  1. 8 March, 17:56
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers