Exercise: Basic Reverse Polish Notation (RPN) Calculator
The RPN notation is also known as postfix expression. The capabilities of the Calculator are as follows:
- Supports operations for sum, difference, division, multiplication.
- Supports floating point operations.
- Use '^' for exponent operator. values entered as "X Y ^" are calculated as X to the power of Y.
- Use '%' for the percent operation. values entered as "X %" are calculated as X/100.
- Use ‘!’ for Factorial (unary operation).
Sample Input and Output:
- Input: 1 2 3 + - Output: -4
- Input: 6 2 * 3 / Output: 4
- Input: 2 3 ^ 4 5 + + Output: 17
- Input: 50 % 2 * Output: 1
- Input: 3 ! 4 5 * + Output: 26
- Input: 12 3 / ! Output: 24
- Input: 5 1 2 + 4 * + 3 - Output: 14
To run this program you've to install Eclipse IDE, Java7 or more and JUnit(Optional).
First Install Java Open Eclipse Import this project Find MainTest.class (shortcut - ctrl+shift+r) and run this file enter your input on console or you can pass parameter in test(input).