Question: 1. Using the following code identify the fault. 2. Using the following code indentify a test case that results in an error, but not a
1. Using the following code identify the fault.
2. Using the following code indentify a test case that results in an error, but not a failure.
public static int lastZero (int[] x) {
//Effects: if x == null throw NullPointerException
//else return the index of the last 0 in x.
//Return -1 if 0 does not occur in x
for (int i = 0; i < x.length; i++)
{
if (x[i] == 0)
{
return i;
}
}
return -1;
}
//test: x = [0, 1, 0]
// Expected = 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
