Advertisement
Ligh7_of_H3av3n

05. Reverse And Exclude

May 27th, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. package Uprajnenie;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import java.util.Scanner;
  7. import java.util.stream.Collectors;
  8.  
  9. public class ReverseAndExclude {
  10.     public static void main(String[] args) {
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13.  
  14.  
  15.  
  16.         String input = scanner.nextLine();
  17.  
  18.         int divisor = scanner.nextInt();
  19.  
  20.         List<Integer> numbers = Arrays.stream(input.split("\\s+"))
  21.                 .map(Integer::parseInt)
  22.                 .collect(Collectors.toList());
  23.  
  24.         List<Integer> result = numbers.stream()
  25.                 .filter(num -> num % divisor != 0)
  26.                 .collect(Collectors.toList());
  27.  
  28.         // Reverse the result list
  29.         Collections.reverse(result);
  30.  
  31.         System.out.println(result.stream()
  32.                 .map(String::valueOf)
  33.                 .collect(Collectors.joining(" ")));
  34.     }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement