Running Total
Easyjava
Start with an initial value in a total variable, then add three more numbers to it one by one. Print the final value of total.
Input: four integers separated by whitespace — the starting value, then three numbers to add.
Output: one line — the final total.
Example 1
Input
100 10 -5 20
Output
125
- -1000000 <= each integer <= 1000000
Hint 1
total = total + sc.nextInt(); repeated three times.
Hint 2
The same variable is reused and updated each time.
One variable, updated three times. This shows that a variable's value changes over the life of the program while its name and type stay the same.