Skip to content

Commit 0f950fe

Browse files
committed
Intersection of Two Arrays
1 parent 6dba46a commit 0f950fe

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

InterviewPrograms/src/com/java/array/ArrayIntersection.java renamed to InterviewPrograms/src/com/java/array/IntersectionOfTwoArrays.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@
66
* Write a Java Program to find the intersection of
77
* Two Arrays
88
*
9-
* say array1 = {1, 2, 3, 4, 5, 6}
10-
* say array2 = {2, 4, 6, 8,10}
9+
* INTERSECTION
10+
* Common element in both arrays.
11+
* Intersection array elements are should be
12+
* present in both array1 and array2
13+
*
14+
* say array1 = {44, 49, 30, 25, 67, 69};
15+
* say array2 = {88, 44, 69, 93, 30};
1116
*
1217
* intersection of two array is
13-
* intersection = {2, 4, 6}
18+
* intersection = {44, 30, 69}
1419
*/
1520

16-
public class ArrayIntersection {
21+
public class IntersectionOfTwoArrays {
1722
public static void main(String[] args) {
18-
int array1[] = {1, 2, 3, 4, 5, 6};
19-
int array2[] = {2, 4, 6, 8, 10};
23+
int array1[] = {44, 49, 30, 25, 67, 69};
24+
int array2[] = {88, 44, 69, 93, 30};
2025

2126
System.out.println("Given array 1 is : ");
2227
for(int v : array1)
@@ -49,8 +54,8 @@ public static void main(String[] args) {
4954
}
5055
/*
5156
OUTPUT
52-
Given array 1 is : 1 2 3 4 5 6
53-
Given array 2 is : 2 4 6 8 10
54-
Intersection of the array 1 & 2 is : 2 4 6
57+
Given array 1 is : 44 49 30 25 67 69
58+
Given array 2 is : 88 44 69 93 30
59+
Intersection of the array 1 & 2 is : 44 30 69
5560
*/
5661

0 commit comments

Comments
 (0)