desislava_topuzakova

05. Reverse And Exclude

Jun 5th, 2021
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.function.BiFunction;
  3. import java.util.function.Consumer;
  4. import java.util.function.Function;
  5. import java.util.function.Predicate;
  6. import java.util.stream.Collectors;
  7.  
  8. public class UserLogs_09 {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.         //Function <приема, връща>
  12.         //Consumer <приема> -> void
  13.         //Supplier <връща>
  14.         //Predicate<приема> -> връща true/false
  15.         //BiFunction<приема1, приема2, връща>
  16.  
  17.         List<Integer> numbers = Arrays.stream(scanner.nextLine().split("\\s+")).mapToInt(Integer::parseInt)
  18.                 .boxed().collect(Collectors.toList()); //1 2 3 4 5 6
  19.         int n = Integer.parseInt(scanner.nextLine());
  20.  
  21.         //обратен ред
  22.         Collections.reverse(numbers);
  23.  
  24.         //премахнем всички числа, които се делят на n
  25.         Predicate<Integer> checkDivision = number -> number % n == 0;
  26.         numbers.removeIf(checkDivision);
  27.  
  28.         //печатаме
  29.         Consumer<List<Integer>> print = list -> list.forEach(e -> System.out.print(e + " "));
  30.         print.accept(numbers);
  31.  
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment