lab-03:
- Add try/catch preventing NumberFormatEx during runtime. No handling yet.
This commit is contained in:
parent
810480828a
commit
d1f38a542b
@ -10,9 +10,14 @@ public class ParseInts {
|
||||
Scanner scanLine = new Scanner(in.nextLine());
|
||||
int sum = 0;
|
||||
while (scanLine.hasNext()){
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user