In postfix (reverse Polish) notation the operator follows its operands: 3 4 + 2 * means (3 + 4) × 2. No parentheses are ever needed.
Write Postfix with static long evaluate(String line) using a Deque<Long> as a stack: push numbers; for an operator pop the right operand, then the left, and push the result. Throw IllegalArgumentException with these messages: operator + needs two operands, division by zero, bad token x, 2 values left on the stack. main evaluates every non-empty input line.
For the input
3 4 + 2 *
5 1 2 + 4 * + 3 -
7 0 /
1 +
2 3
10 4 -
the program prints
3 4 + 2 * = 14
5 1 2 + 4 * + 3 - = 14
7 0 / -> error: division by zero
1 + -> error: operator + needs two operands
2 3 -> error: 2 values left on the stack
10 4 - = 6