-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem008.java
More file actions
26 lines (26 loc) · 872 Bytes
/
Problem008.java
File metadata and controls
26 lines (26 loc) · 872 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
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Problem8 {
public static void main(String[] args) throws FileNotFoundException {
Scanner fileScan = new Scanner(new File("Problem8Text"));
String numbers = "";
while (fileScan.hasNext()) {
numbers += fileScan.nextLine().trim();
}
String lString = "";
double largest = 0;
for (int i = 13; i <= 1000; i++) {
String[] split = numbers.substring(i - 13, i).split("");
double total = 1;
for (String s : split) {
total *= Integer.parseInt(s);
}
if (total > largest) {
lString = numbers.substring(i - 13, i);
largest = total;
}
}
System.out.printf("%f\n", largest);
}
}