- #1

muna580

Code:

```
public int evaluateRPN()
{
StringTokenizer token = StringTokenizer(postfix);
stk.clear();
try
{
while(token.hasMoreTokens())
{
String s = token.nextToken();
if(isNumber(s))
stk.push(new Integer(Integer.parseInt(s)));
else
{
char operator = s.charAt(0);
int x1 = ((Integer)stk.pop()).valueOf();
int x2 = ((Integer)stk.pop()).valueOf();
int x3;
switch(operator)
{
case StackConstants.ADDITION_OPERATOR:
x3 = x2 + x1;
stk.push(new Integer(x3));
break;
case StackConstants.SUBTRACTION_OPERATOR:
x3 = x2 - x1;
stk.push(new Integer(x3));
break;
case StackConstants.MULTIPLICATION_OPERATOR:
x3 = x2 * x1;
stk.push(new Integer(x3));
break;
case StackConstants.DIVISION_OPERATOR:
x3 = x2 / x1;
stk.push(new Integer(x3));
break;
case StackConstants.MODULUS_OPERATOR:
x3 = x2 % x1;
stk.push(new Integer(x3));
break;
}
}
}
}
catch(EmptyStackException e)
{
}
return ((Integer)stk.pop()).valueOf();
}
```