- public class Demo2 {
-
- public static void main(String[] args) {
- Student s1 = new Student("01", "张三", 10, 170);
- Student s2 = new Student("02", "李四", 20, 175);
- Student s3 = new Student("03", "马五", 20, 175);
- Student s4 = new Student("04", "王六", 20, 175);
- Student s5 = new Student("05", "孙七", 23, 180);
- Student s6 = new Student("06", "陈八", 23, 180);
- Student s7 = new Student("07", "赵九", 30, 160);
- Student s8 = new Student("08", "吴十", 30, 160);
- Student[] stus1 = {s1,s2,s3,s4,s5,s6,s7,s8};
- for(int i = 0 ; i < stus1.length;i++){
- for(int j = 0 ; j < stus1.length;j++){
- if(i != j && stus1[i]!= null &&stus1[j] != null && stus1[i].equals(stus1[j])){
- stus1[j]=null;
- }
- }
- }
- for(int i = 0 ; i < stus1.length;i++){
- System.out.println(stus1[i] == null ? "" : stus1[i].toString());
- }
- }
- }
- class Student{
- private String no;
- private String name;
- private int age;
- private int height;
-
- public Student(String no, String name, int age, int height) {
- super();
- this.no = no;
- this.name = name;
- this.age = age;
- this.height = height;
- }
- public String getNo() {
- return no;
- }
- public void setNo(String no) {
- this.no = no;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public int getHeight() {
- return height;
- }
- public void setHeight(int height) {
- this.height = height;
- }
- public boolean equals(Student stu) {
- return (this.age+""+this.height).equals(stu.getAge()+""+stu.getHeight());
- }
- @Override
- public String toString() {
- return "Student [no=" + no + ", name=" + name + ", age=" + age
- + ", height=" + height + "]";
- }
-
- }
复制代码
实现的方法用的最简单无脑的,剩下的自己思考吧,如果看不懂找我给你加注释哈 |