Running Bill with +=
Easyjava
Start from a given total, then add several item prices one by one using +=.
Input: the first line is the starting total; the second line is an integer N; the third line has N prices separated by spaces.
Output: one line — the final total after adding every price.
Example 1
Input
0 3 10 20 5
Output
35
- 0 <= starting total <= 1000000
- 1 <= N <= 100
- 0 <= each price <= 100000
Hint 1
Loop n times; each iteration: total += sc.nextLong();
Hint 2
Print total once after the loop.
A single total variable is updated in place with += for each price. This is the everyday use of compound assignment: accumulate into one running variable.