Software project Management jobs (II.)

Source: Internet
Author: User

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.)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.