All pastes #232367 Raw Edit

Someone

public java v1 · immutable
·published 2006-11-01 09:35 UTC
rendered paste body
    public static double evaluate(String expression)    {        Stack stack = new Stack();        double first = 0.0;        double second = 0.0;                StringTokenizer tokenizer;        tokenizer = new StringTokenizer (expression);        while (tokenizer.hasMoreTokens()) {            char word = tokenizer.nextToken().charAt(0);            if(word == '+' || word == '-' || word == '*' || word == '/') {                    first = Double.parseDouble(stack.pop().toString());                    second = Double.parseDouble(stack.pop().toString());                }                switch (word) {                    case '+': stack.push(new Double(first + second)); break;                    case '-': stack.push(new Double(second - first)); break;                    case '*': stack.push(new Double(first * second)); break;                    case '/': stack.push(new Double(second / first)); break;                    default: stack.push(new Double(word - '0')); break;                }                          }                 // finish this method                return Double.parseDouble(stack.pop().toString());// change the 0.0 to the answer off of the stack    }// end evaluate