i'm having a problem with my code for evaluating postfix expressions. any comments on what's wrong on my code?
import java.io.*;
import java.util.*;
import java.util.Stack;
public class Eval
{
private Stack<String> operatorStack;
private Stack<Integer> operandStack;
public int evaluate(String output)
{
StringTokenizer s = new StringTokenizer(output);//divides into tokens
int value;
String symbol;
while (s.hasMoreTokens())
{
symbol = s.nextToken();
if (Character.isDigit(symbol.charAt(0)))// if its a number push it
{
Integer operand = new Integer(Integer.parseInt(symbol));
operandStack.push(operand);
}
else // if it's an operator, operate on the previous two popped operandStack items
{
int op2 = ((Integer)operandStack.pop()).intValue();
int op1 = ((Integer)operandStack.pop()).intValue();
int result = 0;
switch(symbol.charAt(0))
{
case '*': {result = op1 * op2; break;}
case '+': {result = op1 + op2; break;}
case '-': {result = op1 - op2; break;}
case '/': {result = op1 / op2; break;}
case '%': {result = op1 % op2; break;}
}
Integer operand = new Integer(result);
operandStack.push(operand);
}
}
value = ((Integer)operandStack.pop()).intValue();
return value;
}
public static void main(String[] args)
{
Eval app = new Eval();
Scanner scan = new Scanner(System.in);
System.out.println("Input postfix expression: ");
String output1 = scan.nextLine();
app.evaluate(output1);
}
}