Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Arrays;
- import java.util.Scanner;
- public class CommonElements_02 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String [] firstArray = scanner.nextLine().split(" ");
- //"Hey hello 2 4".split(" ") -> ["Hey", "hello", "2", "4"]
- String [] secondArray = scanner.nextLine().split(" ");
- //"10 hey 4 hello".split(" ") -> ["10", "hey", "4", "hello"]
- //всеки елемент от втория масив -> някой елемент от първия (всеки елемент от първия)
- for (String element2 : secondArray) {
- for (String element1 : firstArray) {
- if (element1.equals(element2)) {
- System.out.print(element1 + " ");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment