Iam新的Java和我有一個Java Person類,我已經創建了人員列表,我可以打印列表,但我不想打印最小和最大年齡一個人名單 我的代碼是Java打印沒有最小值和最大值的列表
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
感謝幫助將不勝感激。
修復格式化! –
你需要保持列表的順序嗎?另外,如果有最老的或最年輕的關係呢? –
我想打印沒有最小和最大年齡的列表 – user1073794