Advertisement
desislava_topuzakova

01.OpinionPoll_Main

Oct 5th, 2020
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package OpinionPoll_01;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Comparator;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8. public class Main {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.         int n = Integer.parseInt(scanner.nextLine());
  12.         List<Person> people = new ArrayList<>();
  13.         for (int i = 0; i < n; i++) {
  14.             String input = scanner.nextLine();
  15.             String name = input.split("\\s+")[0];
  16.             int age = Integer.parseInt(input.split("\\s+")[1]);
  17.  
  18.             if(age > 30) {
  19.                 Person person = new Person(name, age);
  20.                 people.add(person);
  21.             }
  22.         }
  23.  
  24.         people.sort(Comparator.comparing(p -> p.getName()));
  25.  
  26.         for (Person person: people) {
  27.             System.out.println(person.getName() + " - " + person.getAge());
  28.         }
  29.  
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement