title: How to calculate the result in Java?
body: <p>I created this code to create random numbers and operators, but how can it calculate and show the result?</p>
  
  <p>What it does now is for example print out: 4+1-3 or 9*2-8 etc.
  I don't know how to calculate the result of 4+1-3 or 9*2-8 and print it out.</p>
  
  <pre><code>public static void main(String[] args) {
      int t = 0;
      String[] operators = {"-", "+", "*"};
      String operator;
      Random r = new Random();
  
      for (int i = 0; i &lt; 3; i++) {
          int randNum = randNums(9, 1);
          operator = operators[r.nextInt(operators.length)];
          System.out.print(randNum);
          if (t &lt; 2) {
              System.out.print(operator);
              t++;
          }
      }
  
  }
  </code></pre>