Below are two faulty programs. Each includes a test case that results in failure.
Answer the following questions (in the next slide) about each program.(1) Identify the fault.(2) If possible, identify a test case that does not execute thefault. (Reachability)(3) If possible, identify a test case that executes the fault, butdoes not result in an error state.(4) If possible identify a test case that results in an error, butnot a failure
1.
public int findLast (int[] x, int y) { //Effects: If x==null throwNullPointerException// else return the index of the last element// in x that equals y.// If no such element exists, return -1for (int i=x.length-1; i > 0; i--){ if (x[i] == y){ return i;}}return -1;}// test: x=[2, 3, 5]; y = 2// Expected = 0(1)it will not check the first element,if only the first is equle to y it will return -1(2)if y=1 the case: [0 2 1](3)if y=1 the case: [0 2 3](4)if y=1 the case: [1 2 3]2.
public static int lastZero (int[] x) { //Effects: if x==null throwNullPointerException// else return the index of the LAST 0 in x.// Return -1 if 0 does not occur in xfor (int i = 0; i < x.length; i++){ if (x[i] == 0){ return i;}} return -1;}// test: x=[0, 1, 0]// Expected = 2(1)it will show the first zero not the last(2)case: [0 1 2](3)case: [1 2 3](4)case: [0 0 0]