Loading...
Loading...
Loading...
An ATM starts with a customer's balance. Then the customer asks for amounts one by one, and 0 means "finish". For each request:
Invalid amount and skip it.Insufficient balance and skip it.Dispensed a, balance b.At the end print Final balance: b.
Final balance: b.Example
Input
5000 1500 250 4000 2000 0
Output
Dispensed 1500, balance 3500 Invalid amount Insufficient balance Dispensed 2000, balance 1500 Final balance: 1500
250 is not a multiple of 100. 4000 is more than the 3500 left.
Try the problem first. Open one hint at a time.
Read amounts in a while (true) loop and break when the amount is 0.
For a bad request, print the message and use continue to jump to the next request.
Only a request that passes both checks reaches the code that changes the balance.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor