Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Arrays_Exercise {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[] first = sc.nextLine().split(" ");
- String[] second = sc.nextLine().split(" "); // take the user's input and make two Arrays
- for (int i = 0; i < second.length; i++) {
- for (int j = 0; j < first.length; j++) { // read the input of the two arrays
- if (second[i].equals(first[j])) { //create IF condition to check for equal elements
- if (i < second.length - 1) { // create condition to check whether the symbol is last
- System.out.print(second[i] + ", "); // if not print the symbol + comma d space
- }else { // else print the symbol without comma and space
- System.out.print(second[i]);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement