我正在修理我的项目,以查找并告诉我哪些学生尝试使用另一个名称进行注册,因此我编写了代码来搜索我的数据列表并找到具有相同ID号的数字如下,但有可能改变或添加东西,所以它不会打印出相同的信息两次
例测试用例我可以阻止我的程序打印重复信息
Student ID 103 is repeating the class as names Mark Wall and Stacy Gwee
Student ID 103 is repeating the class as names Stacy Gwee and Mark Wall
for(int n = 0; n<studentList.size(); n++)
{
for(int m = 0; m<studentList.size(); m++)
{
if(studentList.get(n).getId().equals(studentList.get(m).getId()) && !studentList.get(n).getName().equals(studentList.get(m).getName()))
{
System.out.println("Student ID " + studentList.get(n).getId() + " is repeating the class as names " + studentList.get(n).getName() + " and " + studentList.get(m).getName());
}
}
}
缩短第二个循环。 – 2014-09-19 20:58:24