CoineTre

JF-ExcArrays02.CommonElements

Jan 20th, 2021 (edited)
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. /* Write a program, which prints common elements in two arrays. You have to compare the elements of the second array to the elements of the first.*/
  2.  
  3. import java.util.Scanner;
  4. public class TestXXX {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         String[] first = scanner.nextLine().split(" ");
  8.         String[] second = scanner.nextLine().split(" ");
  9.         for (String s2 : second) {
  10.             for (String s1 : first) {
  11.                 if (s2.equals(s1)){
  12.                     System.out.print(s2 + " ");
  13.                 }
  14.             }
  15.         }
  16.     }
  17. }
Add Comment
Please, Sign In to add comment