title: Postfix Evaluation using Stacks.
body: <p>I'm going insane..I'm so close to getting this code to work the way I want to I just can't figure it out. I'm trying to solve a postfix equation for ex. 3 2 +  , this equals 5. When I put for example 
  "3 2 +" in the mainmethod it works fine but as soon as I enter a 3rd digit like "3 2 + 2 *" (which equals 10) I get a arrayoutofboundserror relating back to number2 = s.pop() as you will see in the code below. Any help is greatly appreciated. </p>
  
  <p>Heres the postfix meethod:</p>
  
  <pre><code>   public int PostfixEvaluate(String e){
          int number1;
          int number2;
          int result=0;
  
          String[] tokens = e.split(" ");
  
              for(int j = 0; j &lt; tokens.length; j++){
                  String token = tokens[j];
              if (!"+".equals(token) &amp;&amp; !"*".equals(token) &amp;&amp; !"-".equals(token) &amp;&amp; !"/".equals(token)) {
                  s.push(Integer.parseInt(token)); 
  
          }   else {
                  String Operator = tokens[j];
                  number1 = s.pop();
                  number2 = s.pop();
                  if (Operator.equals("/")){
                      result = number1 / number2;}
                  else if(Operator.equals("*")){
                      result = number1 * number2;}
                  else if(Operator.equals("+")){
                      result = number1 + number2;}
                  else if(Operator.equals("-")){
                      result = number1 - number2;}
                  else System.out.println("Illeagal symbol");
              }
                  s.push(result);
  
                      s.pop();
                  }
  
  
          //s.pop();
          System.out.println("Postfix Evauation = " + result);
  
              return result;
  }
  
  public static void main(String[] args) {
      Stacked st = new Stacked(100);
      //String y = new String("((z * j)/(b * 8) ^2");
      String x = new String("2 2 2 * +");
      TestingClass clas = new TestingClass(st);
  
      //clas.test(y);
       clas.PostfixEvaluate(x);
  
      }
  </code></pre>
  
  <p>}</p>