我是java新手,我有一个Java Person类,我创建了一个人员列表,我可以打印该列表,但我不想打印人员列表中的最小和最大年龄我的代码是
public class Person {
static String name;
static String lname;
static double age;
Person(String name,string lname,double age) {
Person.name = name;
Person.lname= lname;
Person.age = age;
}
}
//Main method
public void testQuestionInput() {
List<Person> persons = new ArrayList<Person>();
persons.add(new Person("Foo", "scientist",5));
persons.add(new Person("Foo", "scientist",4));
persons.add(new Person("Foo", "teacher",10));
persons.add(new Person("Bar", "student",11));
persons.add(new Person("Foo", "scientist",12));
for (Person person : _persons ) {
System.out.print(person);
}
}
我可以打印列表,但我想打印一个列表,在我的情况下我必须跳过最大和最小年龄我想打印列表而不
"Foo", "scientist",4 and "Foo", "scientist",12
感谢帮助将不胜感激。