public class Calculator { static boolean isDelim(char c) { return c == ' '; } static boolean isOperator(char c) { return c == '+'|| c == '-'|| c == '/' || c == '*' || c == '%'; } static int priority(char op) { switch(op) { case '+': case '-': return 1; case '*': case '/': case '%': return 2; default: return -1; } } static void processOperator(LinkedList st, char op) { int r = st.removeLast(); int l = st.removeLast(); switch(op){ case '+': st.add(l + r); break; case '-': st.add(l - r); break; case '*': st.add(l * r); break; case '/': st.add(l / r); break; case '%': st.add(l % r); break; } } public static int eval(String s) { LinkedListst = new LinkedList(); LinkedListop = new LinkedList(); for(int i = 0; i < s.length(); i ++) { char c = s.charAt(i); if (isDelim(c)) continue; if (c == '(') op.add('('); else if (c == ')') { while(op.getLast()!='(') processOperator(st, op.removeLast()); op.removeLast(); } else if (isOperator(c)) { while (!op.isEmpty() && priority(op.getLast())>=priority(c)) processOperator(st, op.removeLast()); op.add(c); } else { String operand = new String(); while(i