Advertisement
Guest User

Untitled

a guest
Jan 27th, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import java.util.Collections;
  2. import java.util.LinkedHashSet;
  3. import java.util.Scanner;
  4. import java.util.Set;
  5.  
  6. public class E02_SetOfElements {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. int firstSize = scanner.nextInt();
  10. int secondSize = scanner.nextInt();
  11. scanner.nextLine();
  12.  
  13. Set<String> nums = new LinkedHashSet<>();
  14. Set<String> nums2 = new LinkedHashSet<>();
  15. Set<String> repeated = new LinkedHashSet<>();
  16.  
  17. for (int i = 0; i < firstSize; i++) {
  18. nums.add(scanner.nextLine());
  19. }
  20. for (int i = 0; i < secondSize; i++) {
  21. nums2.add(scanner.nextLine());
  22. }
  23.  
  24. for (String num : nums) {
  25. if (nums2.contains(num)) {
  26. repeated.add(num);
  27. }
  28. }
  29. for (String num : repeated) {
  30. System.out.println(num + " ");
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement