Fixed bug that caused error when EOF reached
Changes to be committed: modified: 2022/day01/CalorieCount.java
This commit is contained in:
parent
77cb70fb39
commit
900ee5e2d1
1 changed files with 8 additions and 4 deletions
|
@ -3,7 +3,7 @@ import java.io.IOException;
|
|||
import java.util.Scanner;
|
||||
|
||||
public class CalorieCount {
|
||||
public static void main(String[] args) {
|
||||
public static void main (String[] args) {
|
||||
try (Scanner inputReader = new Scanner(Paths.get("input.txt"))) {
|
||||
int maxCals = 0;
|
||||
while (inputReader.hasNext()) {
|
||||
|
@ -13,12 +13,16 @@ public class CalorieCount {
|
|||
inLine = inputReader.nextLine();
|
||||
if (!inLine.isEmpty()) {
|
||||
currentCals += Integer.parseInt(inLine);
|
||||
System.out.printf("Current elf total is %d%n", currentCals);
|
||||
}
|
||||
} while (!inLine.isEmpty());
|
||||
} while (!inLine.isEmpty() && inputReader.hasNext());
|
||||
|
||||
if (currentCals > maxCals) {maxCals = currentCals;}
|
||||
if (currentCals > maxCals) {
|
||||
maxCals = currentCals;
|
||||
System.out.printf("New Max Cals: %d%n", maxCals);
|
||||
}
|
||||
}
|
||||
System.out.printf("The large calories carried is: %d", maxCals);
|
||||
System.out.printf("The large calories carried is: %d%n", maxCals);
|
||||
} catch (IOException e) {
|
||||
System.out.println("IOException");
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Reference in a new issue