title: Reverse Polish Notation Java
body: <p>I want to make Reverse Polish Notation algorithm, but my code isn't working. Can anyone explain me why ?
  In my code, I would like to take the characters, until "/+-*"tokens . If this tokens was next , make operation , that contains in case . </p>
  
  <pre><code>import java.util.Stack;
  import java.util.StringTokenizer;
  
  import javax.swing.JOptionPane;
  
  public class ONP {
  
      public static void main(String[] args) {
          Stack&lt;Double&gt; stack = new Stack&lt;Double&gt;();
          double number1;
          double number2;
  
          String x = JOptionPane.showInputDialog("Tokens");
          StringTokenizer str = new StringTokenizer(x);
  
          while (str.hasMoreElements()) {
              str.nextElement();
              stack.push((Double) str.nextElement());
  
              for (int i = 0; i &lt; x.length(); i++) {
  
                  switch (x.charAt(i)) {
                  case '+':
                      number1 = stack.pop();
                      number2 = stack.pop();
                      System.out.println(number1 + number2);
                      break;
                  case '-':
                      number1 = stack.pop();
                      number2 = stack.pop();
                      System.out.println(number1 - number2);
                      break;
                  case '/':
                      number1 = stack.pop();
                      number2 = stack.pop();
                      System.out.println(number1 / number2);
                      break;
                  case '*':
                      number1 = stack.pop();
                      number2 = stack.pop();
                      System.out.println(number1 * number2);
                      break;
                  }
  
              }
              System.out.println(stack.pop());
          }
      }
  
  }
  </code></pre>
  
  <p>I would like to write it without StringBuilder or sth like that.</p>
  
  <p>Input:</p>
  
  <pre><code>2 2 + 2 / 2 /
  </code></pre>
  
  <p>Output :</p>
  
  <pre><code>(2+2) / 2 / 2
  </code></pre>