public class ExprCompute {
    Stack stack;
    String ops = "+-*/";

    public ExprCompute() {
    }

    public double eval(String[] exprs) throws Exception {
	stack = new Stack();
	for (String expr : exprs) {
	    if (ops.contains(expr)) {
		double v2 = Double.parseDouble(stack.pop());
		double v1 = Double.parseDouble(stack.pop());
		double result;
		if (expr.equals("+")) {
		    result = v1 + v2;
		} else if (expr.equals("-")) {
		    result = v1 - v2;
		} else if (expr.equals("*")) {
		    result = v1 * v2;
		} else if (expr.equals("/")) {
		    result = v1 / v2;
		} else {
		    throw new Exception("Invalid expression");
		}
		stack.push(Double.toString(result));
	    } else {
		stack.push(expr);
	    }
	}
	if (stack.count() != 1) {
	    throw new Exception("Invalid expression");
	}
	return Double.parseDouble(stack.pop());
    }

    public static void p(Object s) {
	System.out.println(s);
    }

    public static void main(String [] args) {
	ExprCompute ec = new ExprCompute();
	try {
	    p(ec.eval(args));
	} catch (Exception e) {
	    System.err.println("The expression was invalid.");
	}
    }
}
