Files
2026-04-07 21:06:51 +05:00

25 lines
662 B
Java

package lr11.task_1;
import java.util.Arrays;
public class e2 {
public static int[] getCommonElements(int[] nums1, int[] nums2) {
return Arrays.stream(nums1)
.filter(num -> Arrays.stream(nums2).anyMatch(n -> n == num))
.distinct()
.toArray();
}
public static void main(String[] args) {
int[] array1 = { 1, 2, 3, 4, 5 };
int[] array2 = { 3, 4, 5, 6, 7 };
int[] resultArray = getCommonElements(array1, array2);
System.out.print("Общие элементы: ");
for (int num : resultArray) {
System.out.print(num + " ");
}
}
}