Die Aufgabe ist alle Personen über 30 zu printen. Das Problem ist nur dass es eine leere Zeile in der Console ist, wie kann ich das lösen ?
Java:
public class OpinionPoll {
private static class Person{
String name;
int age;
public String getName(){
return name;
}
public int getAge(){
return age;
}
Person(String n, int a){
this.name = n;
this.age = a;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
List<Person> people = new ArrayList();
String [] line = sc.nextLine().split(" ");
for(int i = 0; i < n; i++) {
Person person = new Person(line[0],
Integer.parseInt(line[1]));
if(person.getAge() > 30) {
people.add(person);
}
line = sc.nextLine().split(" ");
}
people.sort(Comparator.comparing(Person::getName));
for(Person per: people) {
System.out.println(per.getName() + " - " + per.getAge());
}
}
}