Advertisement
petar088

Untitled

Oct 2nd, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. package _7_SETS_AND_MAPS_ADVANCED.Exercise;
  2.  
  3. import java.util.Arrays;
  4. import java.util.LinkedHashSet;
  5. import java.util.Scanner;
  6. import java.util.Set;
  7.  
  8. public class _2_Sets_Of_Elements {
  9. public static void main(String[] args) {
  10. Scanner sc = new Scanner(System.in);
  11.  
  12. int[] nAndM = Arrays.stream(sc.nextLine().split("\\s+"))
  13. .mapToInt(Integer::parseInt).toArray();
  14. int nLength = nAndM[0];
  15. int mLength = nAndM[1];
  16.  
  17. Set<Integer> n = new LinkedHashSet<>();
  18. Set<Integer> m = new LinkedHashSet<>();
  19.  
  20. for (int i = 0; i < nLength; i++) {
  21. n.add(Integer.parseInt(sc.nextLine()));
  22. }
  23.  
  24. Set<Integer> repeating = new LinkedHashSet<>();
  25.  
  26. for (int i = 0; i < mLength; i++) {
  27. int newNumb = Integer.parseInt(sc.nextLine());
  28.  
  29. m.add(newNumb);
  30.  
  31. }
  32. n.forEach(e-> {
  33. if(m.contains(e)){
  34. repeating.add(e);
  35. }
  36. });
  37.  
  38. repeating.forEach(e-> System.out.print(e+" "));
  39.  
  40.  
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement