title: Shorter solution to if,else if,else if
body: <p>I'm looking for a way to shorten this code up and avoid repeating code and if  statements. What I'm doing is creating a calculator that searches strings for operators &quot;* / + - &quot; and executes them accordingly. Any ideas?</p>
  <pre class="lang-java prettyprint-override"><code>if (exp.charAt(i) == '*') {
      newResult = Integer.parseInt(exp.substring(0, i)) * Integer.parseInt(exp.substring(i + 1, exp.length()));
      primeResult = newResult;
      System.out.println(primeResult);
  } else if (exp.charAt(i) == '/') {
      newResult = Integer.parseInt(exp.substring(0, i)) / Integer.parseInt(exp.substring(i + 1, exp.length()));
      primeResult = newResult;
      System.out.println(primeResult);
  } else if (exp.charAt(i) == '+') {
      newResult = Integer.parseInt(exp.substring(0, i)) + Integer.parseInt(exp.substring(i + 1, exp.length()));
      primeResult = newResult;
      System.out.println(primeResult);
  } else if (exp.charAt(i) == '-') {
      newResult = Integer.parseInt(exp.substring(0, i)) - Integer.parseInt(exp.substring(i + 1, exp.length()));
      primeResult = newResult;
      System.out.println(primeResult);
  }
  </code></pre>
  <p>Also, is there a solution to accept a string with more than 2 operands? i.e. 5 + 10 * 2 / 3</p>