-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem011.java
More file actions
55 lines (53 loc) · 1.88 KB
/
Problem011.java
File metadata and controls
55 lines (53 loc) · 1.88 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
45
46
47
48
49
50
51
52
53
54
55
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Problem11 {
public static void main(String[] args) throws FileNotFoundException {
int[][] nums = new int[20][20];
Scanner fileScan = new Scanner(new File("problem11nums"));
int row = 0;
while (fileScan.hasNext()) {
int col = 0;
String line = fileScan.nextLine();
for (String s : line.split(" ")) {
nums[row][col] = Integer.parseInt(s.trim());
col++;
}
row++;
}
int largest = 0;
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++) {
if (i < 17) {
int temp = nums[i][j] * nums[i+1][j] * nums[i+2][j]
* nums[i+3][j];
if (temp > largest) {
largest = temp;
}
if (j < 17) {
int temp1 = nums[i][j] * nums[i+1][j+1] * nums[i+2][j+2]
* nums[i+3][j+3];
if (temp1 > largest) {
largest = temp1;
}
}
if (j > 3) {
int temp2 = nums[i][j] * nums[i+1][j-1] * nums[i+2][j-2]
* nums[i+3][j-3];
if (temp2 > largest) {
largest = temp2;
}
}
}
if (j < 17) {
int temp = nums[i][j] * nums[i][j+1] * nums[i][j+2]
* nums[i][j+3];
if (temp > largest) {
largest = temp;
}
}
}
}
System.out.println(largest);
}
}