publicstaticvoidmain(String[] args) { Stack<Integer> num=newStack<>(); Stack<Character> oper=newStack<>(); String express="322+3*6-2"; for (inti=0; i < express.length(); i++) { char ch=express.charAt(i); if (isoper(ch)){ if (!oper.isEmpty()){ char ch1=oper.peek(); if (priority(ch)<=priority(ch1)){ int num1=num.pop(); int num2=num.pop(); char ch3=oper.pop(); int result=result(num1,num2,ch3); num.push(result); oper.push(ch); }else { oper.push(ch); }
while (!oper.isEmpty()){ int num1=num.pop(); int num2=num.pop(); char ch=oper.pop(); int result=result(num1,num2,ch); num.push(result); } System.out.println(num.peek()); }