Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package OpinionPoll;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.List;
- public class Main {
- public static void main(String[] args) throws IOException {
- BufferedReader reader =
- new BufferedReader(
- new InputStreamReader(
- System.in));
- System.out.println("Number of people ");
- int n = Integer.parseInt(reader.readLine());
- List<Persons> people = new ArrayList<>();
- while (n -- > 0) {
- System.out.println("Person - age ");
- String []data = reader.readLine().split("\\s+");
- Persons persons = new Persons(data[0], Integer.parseInt(data[1]));
- people.add(persons);
- }
- /*people.stream().filter(persons -> persons.getAge() >= 20)
- .sorted(Comparator.comparingInt(Persons::getAge))
- .forEach(persons -> {
- System.out.println(persons.toString());
- });*/
- people.stream().filter(persons -> persons.getAge() >= 20)
- .sorted((p2, p1) -> p1.getName().compareTo(p2.getName()))
- .forEach(persons -> {
- System.out.println(persons.toString());
- });
- }
- package OpinionPoll;
- public class Persons {
- private String name;
- private int age;
- public Persons(String name, int age) {
- this.name = name;
- this.age = age;
- }
- public String getName() {
- return this.name;
- }
- public int getAge() {
- return this.age;
- }
- @Override
- public String toString() {
- return String.format("%s - %d", name, age);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement