Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a JAVA question. Conside the following instance variable and method. pri

ID: 3836691 • Letter: T

Question

This is a JAVA question.

Conside the following instance variable and method.

private int [] numbers;

public int mystery(int num)

{ for (int k = numbers.length -1; k>= 0; k--)

{if (numbers[k] < num) return k;

} return -1;}

Which of the following best describes the contents of numbers after the following statement has been executed?

int m = mystery(n);

a) All values in positions 0 through m are less than n.

b) all values in positions m+1 through number.length - 1 are less than n

c) all values in positions m+1 through numbers.length - 1 are greater than or equal to n

d) The smaller value is at position m

e) The larger value that is smaller than n is at position m

Explanation / Answer


int m = mystery(n);
Ans: c) all values in positions m+1 through numbers.length - 1 are greater than or equal to n

private int [] numbers;
public int mystery(int num)
{
   for (int k = numbers.length -1; k>= 0; k--)
   {
       if (numbers[k] < num)
           return k;
   }
   return -1;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote