做考试答案判断时,考试多选题正确答案可能是多个如{“a”, “b”, “c”},但可能出现不同的选择顺序,所以要对其进行判断
代码实现如下
@Test
public void test1() {
String[] rightAnswer = {"a", "b", "c"};
// bac cba ...不管什么顺序结果都一样
String[] reply = {"a", "c", "b"};
Arrays.sort(rightAnswer);
Arrays.sort(reply);
//结果为 两个数组中的元素值相同
if (Arrays.equals(rightAnswer, reply)) {
System.out.println("两个数组中的元素值相同");
} else {
System.out.println("两个数组中的元素值不相同");
}
}
@Test
public void test2() {
String[] s1 = {"a", "b", "c"};
// bac cba ...不管什么顺序结果都一样
String[] s2 = {"a", "c", "b"};
List rightAnswer = Arrays.asList(s1);
List reply1 = Arrays.asList(s2);
Boolean judge = true;
for (String s : reply1) {
if (!rightAnswer.contains(s)) {
judge = false;
break;
}
}
//结果为 两个数组中的元素值相同
if (judge) {
System.out.println("两个数组中的元素值相同");
} else {
System.out.println("两个数组中的元素值不相同");
}
}



