Advertisement
deyanmalinov

02. Sets of Elements

Jun 1st, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.util.LinkedHashSet;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.     public static void main(String[] args){
  8.         Scanner scan = new Scanner(System.in);
  9.         int fNum = scan.nextInt();
  10.         int sNum = scan.nextInt();
  11.         LinkedHashSet<Integer> fSet = new LinkedHashSet<>();
  12.         LinkedHashSet<Integer> sSet = new LinkedHashSet<>();
  13.         for (int i = 0; i < fNum; i++) {
  14.             int num = scan.nextInt();
  15.             fSet.add(num);
  16.         }
  17.         for (int i = 0; i < sNum; i++) {
  18.             int num = scan.nextInt();
  19.             sSet.add(num);
  20.         }
  21.         fSet.retainAll(sSet);
  22.  
  23.         for (Integer integer : fSet) {
  24.             System.out.print(integer+ " ");
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement