Loading...
Loading...
Loading...
At closing time the canteen cashier types the amount of every bill of the day. A negative number means "no more bills". Print how many bills there were and their average, rounded to 2 decimal places.
If the very first number is negative, there were no bills: print No bills.
No bills, or two lines: Bills: c and Average: x, where x has exactly 2 decimal places.Example 1
Input
120 80 45 -1
Output
Bills: 3 Average: 81.67
245 / 3 = 81.666..., shown as 81.67.
Example 2
Input
-1
Output
No bills
No bills at all.
Try the problem first. Open one hint at a time.
You do not know how many numbers will come. Use while (true) and break as soon as a negative number is read.
Add each bill to a total and count it. Do not add the end marker.
Divide as double (cast the total first) and print with printf("%.2f").
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor