Don't iterate the sums, just use Collections.max
This commit is contained in:
parent
ebd77b57d4
commit
7e8ce94b5a
1 changed files with 2 additions and 10 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Collections;
|
||||
import java.util.Scanner;
|
||||
|
||||
class Part1 {
|
||||
|
|
@ -27,16 +27,8 @@ class Part1 {
|
|||
}
|
||||
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.println(largest);
|
||||
System.out.println(Collections.max(sums));
|
||||
}
|
||||
|
||||
private static Scanner readFile(String file) throws FileNotFoundException {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue