Homework One
public int FindLast (int[] x, int y) {
Effects:if X==null Throw NullPointerException
else return the index of the last element
In x that equals Y.
If No such element exists, return-1
for (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) The For loop should end at i<=0
2) x=[] The pointer is empty and cannot reach fault
3) x=[1,2,3],y=2 fault reachable at this time without causing error status
4) x=[3,4,5],y=2 causes error
Homework Two
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
1) The loop should be changed to for (int i = x.length-1; I >= 0; i++)
2) The pointer is abnormal, no matter how it will enter the loop, enter the loop to enter the fault
3) x=[0], at which point the program arrives at the fault statement, but does not cause the error state
4) x=[0,1,2] Cause error
Software project Management jobs (II.)