-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayAbsurdity.java
More file actions
34 lines (31 loc) · 865 Bytes
/
ArrayAbsurdity.java
File metadata and controls
34 lines (31 loc) · 865 Bytes
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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class ArrayAbsurdity {
int sum;
int n;
int expectVal;
public ArrayAbsurdity(String filename) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(filename));
String line;
int i;
while ((line = br.readLine())!= null) {
String[] params = line.split(";");
n = Integer.parseInt(params[0]);
expectVal = n*(n-1)/2;
sum = 0;
String[] vals = params[1].split(",");
for (i = 0; i < n; i++) {
sum+=Integer.parseInt(vals[i]);
}
System.out.println(sum + (n - 1) - expectVal);
}
}
public static void main(String[] args) throws IOException {
if (args.length != 1) {
System.out.println("Unexpected number of parameters. Exiting.");
System.exit(1);
}
ArrayAbsurdity aa = new ArrayAbsurdity(args[0]);
}
}