lr11 -> task_1 -> e2-4
This commit is contained in:
24
lr11/task_1/e2.java
Normal file
24
lr11/task_1/e2.java
Normal file
@@ -0,0 +1,24 @@
|
||||
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 + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user