title: evaluating a postfix expression eg
body: <p>i am trying to evaluating a postfix expression, i can do it for characters, but tried to do it this time with numbers and not just single digits. here is my code, </p>
  
  <pre><code>package test;
  
  import java.util.Stack;
  
  public class EvaluatePostfix {
  
  public static int solution(String postfix){
  
      Stack&lt;Integer&gt; stack = new Stack&lt;Integer&gt;();
      int sum = 0;
      int val1 = 0;
      int val2 = 0;
      String[] str = postfix.split(" ");
  
  
      for(int i =0; i&lt;str.length; i++){
          if(Character.isDigit(postfix.charAt(i))){
              stack.push(Integer.parseInt(str[i]));
              System.out.println(stack.peek());
          }
          else{
              //System.out.println(stack.peek());
              val1 = stack.pop();
              val2 = stack.pop();
  
              switch(str[i].charAt(0)){
  
              case '+':
                  stack.push(val1 + val2);
                  sum += val2;
                  break;
              case '-':
                  stack.push(val1 - val2) ;
                  sum -= val2;
                  break;
              case '/':
                  stack.push(val1 / val2) ;
                  sum /= val2;
                  break;
              case '*':
                  stack.push(val1 * val2) ;
                  sum *= val2;
                  break;
              }
              //System.out.println(sum);
          }
          //System.out.println(stack.pop());
      }
  
      return stack.pop();
  
  
  }
  
  public static void main(String[]args){
  
      String test = "10 20 30 * +";
      //solution(test);
  
      System.out.println(solution(test));
  
  }
  
  }
  </code></pre>
  
  <p>i have 10, 20 as output it doesnt outputs 30 * +  </p>
  
  <p>i also have an error which says the following, </p>
  
  <pre><code>Exception in thread "main" java.lang.NumberFormatException: For input string: "*"
  at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
  at java.lang.Integer.parseInt(Integer.java:449)
  at java.lang.Integer.parseInt(Integer.java:499)
  at test.EvaluatePostfix.solution(EvaluatePostfix.java:18)
  at test.EvaluatePostfix.main(EvaluatePostfix.java:60)
  </code></pre>
  
  <p>i dont know why i have that error, i clearly check that str[i] is a digit, * is not a digit so why does it try to convert to a digit;  </p>
  
  <p>Thanks</p>