-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem018.java
More file actions
27 lines (27 loc) · 934 Bytes
/
Problem018.java
File metadata and controls
27 lines (27 loc) · 934 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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
public class Problem18 {
public static void main(String[] args) throws FileNotFoundException {
Scanner fileScan = new Scanner(new File("problem18nums"));
int[][] nums = new int[15][];
int i = 0;
while (fileScan.hasNext()) {
String[] temp = fileScan.nextLine().split(" ");
nums[i] = new int[temp.length];
for (int j = 0; j < temp.length; j++) {
nums[i][j] = Integer.parseInt(temp[j].trim());
}
i++;
}
for (i = 13; i >= 0; i--) {
for (int j = 0; j < nums[i].length; j++) {
int num1 = nums[i+1][j];
int num2 = nums[i+1][j+1];
nums[i][j] += num1 > num2 ? num1 : num2;
}
}
System.out.println(nums[0][0]);
}
}