构造一个尽可能简单的程序P(包含两个Faults: F1和F2),同时构造t1, t2和t3,使得
- t1单独执行到F1并且发现Failure;
- t2单独执行到F2并且发现Failure;
- t3同时执行到F1和F2,并且能够对F1产生Error,但没有Failure。//请标明详细注释
public class Test {
public static void P(int [] numbers){
int lenth = numbers.length;
double mean,sum;
sum = 0.0;
if (lenth > 2 )
{
for (int i = 1; i < lenth; i++) {
sum += numbers[i];
}
mean = sum / (double) lenth;
System.out.println("Mean:" + mean);
}
if (lenth <= 4 )
{
int max = numbers[0];
for (int i = 1; i < lenth; i++) {
if (numbers[i] < max)
{
max = numbers[i];
}
}
System.out.println("Max:" + max );
}
}
public static void main(String[] args) {
int t1[] = {2, 3, 5, 6, 9};
int t2[] = {5, 6};
int t3[] = {0, 5, 4};
System.out.print("t1期待输出:Mean:5,实际输出:");
P(t1);
System.out.println("----------------------------------");
System.out.print("t2期待输出:Max:6,实际输出:");
P(t2);
System.out.println("----------------------------------");
System.out.print("t3期待输出:\n" + "Mean:3.0" + "\n" + "Max:5\n" + "实际输出:\n");
P(t3);
System.out.println("----------------------------------");
}
}