乱数と演算子を作成するためにこのコードを作成しましたが、どのように計算して結果を表示できますか?
たとえば、4+1-3 または 9*2-8 などを出力します。4+1-3 または 9*2-8 の結果を計算して出力する方法がわかりません。
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++;
}
}
}