lab-03:
- Add try/catch preventing NumberFormatEx during runtime. No handling yet.
This commit is contained in:
parent
810480828a
commit
d1f38a542b
@ -10,8 +10,13 @@ public class ParseInts {
|
|||||||
Scanner scanLine = new Scanner(in.nextLine());
|
Scanner scanLine = new Scanner(in.nextLine());
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
while (scanLine.hasNext()){
|
while (scanLine.hasNext()){
|
||||||
int val = Integer.parseInt(scanLine.next());
|
try {
|
||||||
sum += val;
|
int val = Integer.parseInt(scanLine.next());
|
||||||
|
sum += val;
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e){
|
||||||
|
//pass
|
||||||
|
}
|
||||||
}
|
}
|
||||||
out.println("The sum of the integers on this line is " + sum);
|
out.println("The sum of the integers on this line is " + sum);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user