import java.util.*;
public class PostfixEvaluation
{
static boolean isOperator(char ch)
{
if(ch == '+' || ch == '-' || ch == '*' || ch == '/')
return true;
return false;
}
static void evaluatePostfix(String exp)
{
Stack<Integer> postFix = new Stack<>();
int n = exp.length();
for(int i=0;i<n;i++)
{
if(isOperator(exp.charAt(i)))
{
int op1 = postFix.pop();
int op2 = postFix.pop();
switch(exp.charAt(i))
{
case '+': postFix.push(op2 + op1);
break;
case '-': postFix.push(op2 - op1);
break;
case '*': postFix.push(op2 * op1);
break;
case '/': postFix.push(op2 / op1);
break;
}
}
else
{
int operand = exp.charAt(i) - '0';
postFix.push(operand);
}
}
System.out.println(postFix.pop());
}
public static void main(String args[])
{
String exp = "823*+7/1-";
System.out.print("The PostFix Evaluation for the Given Expression "+exp+" is: ");
evaluatePostfix(exp);
}
}