Apply Four Operations
Mediumjava
Start from a value, then apply four operations in order using compound assignment, printing the value after each step.
Input: the first line is the starting integer; then four lines, each an operator (+, -, * or /) and an integer, separated by a space. Division is integer division and the divisor is never zero.
Output: four lines — the value after each operation.
Example 1
Input
100 + 50 - 20 * 2 / 13
Output
150 130 260 20
- values stay within the range of a 64-bit integer
Hint 1
Use a switch (or if chain) on op to pick the compound operator.
Hint 2
Print value inside the loop, right after updating it.
Read each operator token and number, then branch to the matching compound assignment (+=, -=, *=, /=). Printing after every step shows the value evolving through one variable.