Skip to content

Commit 8b66a4b

Browse files
authored
Create SetIntersection.java
1 parent 905d77f commit 8b66a4b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Easy-Level/SetIntersection.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
You are given two sorted list of numbers (ascending order). The lists themselves are comma delimited and the two lists are semicolon delimited. Print out the intersection of these two sets.
3+
*/
4+
5+
import java.io.*;
6+
public class Main {
7+
public static void main (String[] args) throws IOException {
8+
File file = new File(args[0]);
9+
BufferedReader br = new BufferedReader(new FileReader(file));
10+
String line;
11+
while ((line = br.readLine()) != null) {
12+
String[] s = line.split(";");
13+
String[] a1 = s[0].split(",");
14+
String[] a2 = s[1].split(",");
15+
String f = "";
16+
for (int i = 0; i < a1.length; i++) {
17+
for (int j = 0; j < a2.length; j++) {
18+
if(a1[i].equals(a2[j])) {
19+
f += a1[i] + ",";
20+
}
21+
}
22+
}
23+
System.out.println(f.replaceFirst(".$",""));
24+
}
25+
br.close();
26+
}
27+
}

0 commit comments

Comments
 (0)