In the inverse Polish notation, operators are placed behind the operands. For example, when "three plus four" is expressed, "3 4 +" is written instead of "3 + 4 ". If there are multiple operators, the operator is placed behind the second operand, so the "3-4 + 5" of the General infix method is in the inverse wave. Write 3 4-5 + in the logging method. "3 minus 4, plus 5. One advantage of using the inverse Polish notation is that parentheses are not needed.
Compile the result of Java function compute inverse polish expression.
Enter a reverse polish expression, 1. the operand type is a positive double number, which complies with Java's double constant specification. Different operation numbers are separated by spaces or operators; 2. Four arithmetic operations are supported, that is, the operators include +,-, *, And ,-,*,/. Output as computing result If the input is "1 2 + 3 *", the output is "9.0" Exam points: 1. A simple expression (50 points) can be correctly processed. For example, the result of 1.0 + 2 is 3.0. 2. Correct Processing of different operators (30 points). For example, the result of 1 2 + 3 * calculation is 9.0. 3. correctly identifies the syntax error (10 points) in the input inverse polish expression. If the input is 1 +, It is thrown. Rpnsyntaxerrorexception exception 4. correct identification of the Division by zero (10 points) in the input inverse polish expression, if the input is 1 2 2 -/ Throwing devidebyzeroexception
|