-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPart1.java
More file actions
35 lines (27 loc) · 998 Bytes
/
Copy pathPart1.java
File metadata and controls
35 lines (27 loc) · 998 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
35
package y2017.d02;
import java.io.File;
import java.util.Scanner;
public class Part1 {
public static void main(String[] args) {
File file = new File("src/main/java/y2017/d02/in.txt");
try {
Scanner scanner = new Scanner(file);
String line = "";
int checksum = 0;
while (scanner.hasNextLine()) {
line = scanner.nextLine();
String[] split = line.split("\t");
int largest = Integer.MIN_VALUE;
int smallest = Integer.MAX_VALUE;
for (String number: split) {
largest = Math.max(Integer.parseInt(number), largest);
smallest = Math.min(Integer.parseInt(number), smallest);
}
checksum += largest - smallest;
}
System.out.println("Checksum: " + checksum);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}