Question: Develop a code in Java to implement the Polish Calculator. Here comes the specification of this calculator: Polish notation, operators follow their operands; for instance,
Develop a code in Java to implement the "Polish Calculator". Here comes the specification of this calculator: Polish notation, operators follow their operands; for instance, to add 3 and 4 together, one would write 3 4 + rather than 3 + 4. If there are multiple operations, operators are given immediately after their final operands (often an operator takes two operands, in which case the operator is written after the second operand); so the expression written 3 4 + 5 in conventional notation would be written 3 4 5 + in reverse Polish notation: 4 is first subtracted from 3, then 5 is added to it. You can read more about this here: https://en.wikipedia.org/wiki/Reverse_Polish_notation
Note: Assume that your calculator works ONLY with integers.
You are required to implement the following:
public int polishCalculator(String expression){
//Your code goes here
}
A user calls your function like: polishCalculator("2 3 +"), in which case, you should return 5.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
