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

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!