- Add try/catch preventing NumberFormatEx during runtime. No handling yet.
This commit is contained in:
HeshamTB 2020-10-02 16:28:26 +03:00
parent 810480828a
commit d1f38a542b
Signed by: Hesham
GPG Key ID: 74876157D199B09E

View File

@ -10,8 +10,13 @@ public class ParseInts {
Scanner scanLine = new Scanner(in.nextLine());
int sum = 0;
while (scanLine.hasNext()){
int val = Integer.parseInt(scanLine.next());
sum += val;
try {
int val = Integer.parseInt(scanLine.next());
sum += val;
}
catch (NumberFormatException e){
//pass
}
}
out.println("The sum of the integers on this line is " + sum);
}