import java.util.Scanner; public class PostfixFilled { public static void main(String [] args) { Stack operands = new Stack(); // We are restricted to single-digit inputs char[] expression = {'7','5','-','4','*','6','1','2','+','/','+'}; for(int i = 0; i < expression.length; i++) { // Case 1: the next token is a number if(Character.isDigit(expression[i])) { // Translate the next character into an int, // then push it onto the operands stack operands.push(Character.getNumericValue(expression[i])); } // Case 2: the next token is an operator else { int b = operands.pop(); int a = operands.pop(); char op = expression[i]; // Our next action depends on what operator we saw if(op == '+') operands.push(a + b); else if(op == '-') operands.push(a - b); else if(op == '*') operands.push(a * b); else operands.push(a / b); } } // Print out the result of the computation System.out.println(operands.pop()); } }