0
0
Fork 0

Don't iterate the sums, just use Collections.max

This commit is contained in:
Oliver Akins 2022-12-02 23:50:33 -06:00
parent ebd77b57d4
commit 7e8ce94b5a
No known key found for this signature in database
GPG key ID: 3C2014AF9457AF99

View file

@ -1,7 +1,7 @@
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Collections;
import java.util.Scanner; import java.util.Scanner;
class Part1 { class Part1 {
@ -27,16 +27,8 @@ class Part1 {
} }
f.close(); f.close();
Iterator<Integer> i = sums.iterator();
Integer largest = Integer.MIN_VALUE;
while (i.hasNext()) {
Integer sum = i.next();
if (sum > largest) {
largest = sum;
}
}
System.out.print("The largest value is: "); System.out.print("The largest value is: ");
System.out.println(largest); System.out.println(Collections.max(sums));
} }
private static Scanner readFile(String file) throws FileNotFoundException { private static Scanner readFile(String file) throws FileNotFoundException {