Created
February 22, 2017 14:48
-
-
Save vanduc1102/71d58cfcc22ce5b7f03be39b92b41d6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Student { | |
private String name; | |
private String mssv; | |
public String getMssv() { | |
return mssv; | |
} | |
public void setMssv(String mssv) { | |
this.mssv = mssv; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
} | |
public class Demo { | |
public static void main(String[] args) { | |
System.out.println("Vui lòng nhập thông tin của 5 sinh viên"); | |
List<Student> students = new ArrayList<>(); | |
Scanner input = new Scanner(System.in); | |
for(int i = 0; i < 5; i++){ | |
Student student = new Student(); | |
System.out.println("Nhập thông tin của student " + (i + 1) + " :"); | |
System.out.println("Tên: "); | |
student.setName(input.nextLine()); | |
System.out.println("MSSV: "); | |
student.setMssv(input.nextLine()); | |
students.add(student); | |
} | |
for (int i = 0; i < students.size(); i++) { | |
boolean flagCompare = false; | |
int order = 0; | |
for (int j = 0; j < students.size(); j++) { | |
if(i == j){ | |
continue; | |
} | |
if(students.get(i).getName().equalsIgnoreCase(students.get(j).getName())){ | |
if(i < j){ | |
continue; | |
}else { | |
flagCompare = true; | |
order = j; | |
break; | |
} | |
} | |
} | |
if(!flagCompare){ | |
System.out.println("Tên sv "+(i + 1)+": " + students.get(i).getName()); | |
System.out.println("MSSV: " +students.get(i).getMssv()); | |
System.out.println(); | |
}else { | |
System.out.println("Sinh viên này bị trùng tên với sinh viên thứ "+(order + 1)+""); | |
System.out.println(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment