Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started