Consider the findLast method and answer the questions.
You may make a copy of a worksheet and complete this activity, or write your answer on paper(s) or your computer.
You may work alone or with another student in this course.
/**
* Find last index of element
*
* @param x array to search
* @param y value to look for
* @return last index of y in x; -1 if absent
* @throws NullPointerException if x is null
*/
line 1 public static int findLast(int[] x, int y)
line 2 {
line 3 if (x == null)
line 4 throw new NullPointerException();
line 5 for (int i=x.length-1; i>0; i--)
line 6 {
line 7 if (x[i] == y)
line 8 return i;
line 9 }
line 10 return -1;
line 11 }
// test: x = [2, 3, 5]; y = 2;
// expected = 0
CC-BY-NC-SA 4.0 license.