Loading...
Loading...
Loading...
A shopkeeper copies the day's UPI amounts from his phone, but some entries got typed wrong, like 12O (with the letter O) or N/A. A refund is a negative amount.
Add up every entry that is a whole number and skip the rest. Print the total and how many entries were skipped.
Total: <sum> and Skipped: <count>.int and is between -10^6 and 10^6Example 1
Input
5 120 45 abc 300 12O
Output
Total: 465 Skipped: 2
abc and 12O are skipped.
Example 2
Input
3 -50 200 N/A
Output
Total: 150 Skipped: 1
A refund of 50 reduces the total.
Try the problem first. Open one hint at a time.
Read each entry with sc.next() as a String, never with nextInt().
Put the parseInt and the addition inside a try inside the loop, so one bad entry does not stop the loop.
In the catch block, add 1 to the skipped count.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor