Question: Consider the following instance variable and method. private int[] nums; // The nums array is initialized on this line public int mystery(int val) { int

Consider the following instance variable and method.

private int[] nums;

// The nums array is initialized on this line

public int mystery(int val)

{

int k = 0;

while (k < nums.length && nums[k] > val)

{

k++;

}

return k;

}

Suppose that the call mystery(10) returns a value of 3. Which of the following could be the values that the nums array are initialized with?

  • {23, 11, 43, 8, 15}

  • {15, 16, 9, 18, 13}

  • {19, 12, 14, 20, 30, 21, 45}

  • {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

  • None of these would correctly result in a returned value of 3.

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!