I created this code to create random numbers and operators, but how can it calculate and show the result?
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.
public static void main(String[] args) {
int t = 0;
String[] operators = {"-", "+", "*"};
String operator;
Random r = new Random();
for (int i = 0; i < 3; i++) {
int randNum = randNums(9, 1);
operator = operators[r.nextInt(operators.length)];
System.out.print(randNum);
if (t < 2) {
System.out.print(operator);
t++;
}
}
}