la-ma-rin

commonElements

Feb 9th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class commonElements {
  4.     public static void main(String[] args) {
  5.         Scanner scan = new Scanner(System.in);
  6.  
  7.  
  8.         String[] arr1 = scan.nextLine().split(" ");
  9.         String[] arr2 = scan.nextLine().split(" ");
  10.  
  11.         for (int i = 0; i <= arr1.length - 1; i++) {
  12.  
  13.             for (int j = 0; j <= arr2.length - 1; j++) {
  14.  
  15.                 if (arr2[j].equals(arr1[i])) {
  16.                     System.out.print(arr2[j] + " ");
  17.                 }
  18.             }
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment