Question: 2 0 . Consider the following method. / * * Precondition: arr.length > 0 * / public static int mystery ( int [ ] arr

20.Consider the following method.
/** Precondition: arr.length >0*/
public static int mystery(int[] arr)
{ int index =0;
int count =0;
int m =-1;
for (int outer =0; outer < arr.length; outer++)
{ count =0;
for (int inner = outer +1; inner < arr.length; inner++)
{ if (arr[outer]== arr[inner])
{ count++; }}
if (count > m)
{ index = outer;
m = count;
}}
return index;
}
Assume that nums has been declared and initialized as an array of integer values. Which of
the following best describes the value returned by the call mystery(nums)?
(A) The maximum value that occurs in nums
(B) An index of the maximum value that occurs in nums
(C) The number of times that the maximum value occurs in nums
(D) A value that occurs most often in nums
(E) An index of a value that occurs most often in nums

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!