public static void main(String[] args) {
//数据库中查询出的正确答案
String str1 = "B,C,D";
//将字符串存入数组中
String [] strings1=str1.split(",");
//前台返回的答案
String [] strings2 = {"b","c","d"};
String [] strings3 = {"B","C","D"};
String [] strings4 = {"D","B","C"};
String [] strings5 = {"D","B","A"};
String [] strings6 = {"D","B","A","C"};
String [] strings7 = {"D","B"};
boolean equals2 = equalsString(strings1,strings2); //false
System.out.println("比较结果为:"+equals2);
boolean equals3 = equalsString(strings1,strings3); //true
System.out.println("比较结果为:"+equals3);
boolean equals4 = equalsString(strings1,strings4); //true
System.out.println("比较结果为:"+equals4);
boolean equals5 = equalsString(strings1,strings5); //false
System.out.println("比较结果为:"+equals5);
boolean equals6 = equalsString(strings1,strings6); //false
System.out.println("比较结果为:"+equals6);
boolean equals7 = equalsString(strings1,strings7); //false
System.out.println("比较结果为:"+equals7);
}
public static boolean equalsString(String[] list1,String[] list2) {
if(list1.length != list2.length){
return false;
}
Arrays.sort(list1);
Arrays.sort(list2);
boolean equals = Arrays.equals(list1, list2);
return equals;
}
比较两个数组是否相同,不包括顺序,考试系统判断答案是否正确
最新推荐文章于 2024-01-04 11:31:52 发布