-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiplyLists.java
More file actions
44 lines (35 loc) · 1.02 KB
/
MultiplyLists.java
File metadata and controls
44 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class MultiplyLists {
int[] prod;
String filename;
public MultiplyLists(String filename) {
this.filename = filename;
}
public void parseData() throws IOException {
BufferedReader br = new BufferedReader(new FileReader(filename));
String line;
while ((line = br.readLine()) != null) {
String[] lists = line.split("\\|");
String[] l1 = lists[0].split("\\s");
String[] l2 = lists[1].split("\\s");
prod = new int[l1.length];
for (int i = 0; i < l1.length; i++) {
prod[i] = Integer.parseInt(l1[i]) * Integer.parseInt(l2[i+1]);
}
for (int i = 0; i < prod.length; i++) {
System.out.print(prod[i] + " ");
}
System.out.println();
}
}
public static void main(String[] args) throws IOException {
if (args.length != 1) {
System.out.println("Unsupported number of parameters passed. Exiting.");
System.exit(1);
}
MultiplyLists ml = new MultiplyLists(args[0]);
ml.parseData();
}
}