题目:
解答:
Program 1:
(1) Fault: ‘for(int i=x.length-1;i>0;i--)’. It should be “i>=0”.
(2) X=[],y=2.
Expected=NullPointerException.
Output=NullPointerException
(3) X=[2,3,5],y=3.
Expected=1
Output=1
(4) X=[1,3,5],y=2.
Expected=-1
Output=-1
Program 2:
(1) Fault: The for-loop should be:
for(int i=x.length-1;i>=0;i--)
(2)It’s impossible.
(3) X=[]
Expected=NullPointerException.
Output=NullPointerException
(4)x=[0,1,2]
Expected=0
Output=0
Summery:
fault - a cause of the error (mistake in coding)
error - incorrect state that may lead to failure
failure - deviation of the service from the correct service
原文:http://www.cnblogs.com/ideal233/p/6442075.html