Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.function.*;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int numberOfInputs = Integer.parseInt(scanner.nextLine());
- ArrayList<ArrayList<String>> data = new ArrayList<>();
- for (int i = 0; i < numberOfInputs; i++) {
- String[] currentData = scanner.nextLine().split(", ");
- ArrayList<String> currentDataLst = new ArrayList<>(Arrays.asList(currentData));
- data.add(currentDataLst);
- }
- String condition = scanner.nextLine();
- int age = Integer.parseInt(scanner.nextLine());
- Predicate<List<String>> filterPeople = lst -> {
- if (condition.equals("older")) {
- return Integer.parseInt(lst.get(1)) >= age;
- }
- return Integer.parseInt(lst.get(1)) <= age;
- };
- String printRes = scanner.nextLine();
- BiConsumer<List<String>, String> printResult = (lst, printType) -> {
- switch (printType) {
- case "name age":
- System.out.format("%s - %s\n", lst.get(0), lst.get(1));
- break;
- case "name":
- System.out.println(lst.get(0));
- break;
- case "age":
- System.out.println(lst.get(1));
- break;
- }
- };
- data.stream()
- .filter(filterPeople)
- .forEach(lst -> printResult.accept(lst, printRes));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment