课后作业一
import java.util.Random;
class RandomArithmeticProblems {
public static void main(String[] args) {
Random random = new Random();
for (int i = 0; i < 30; i++) {
int num1 = random.nextInt(100);
int num2 = random.nextInt(100);
int operator = random.nextInt(4);
int result;
switch (operator) {
case 0:
result = num1 + num2;
System.out.println(num1 + " + " + num2 + " = ");
break;
case 1:
result = num1 - num2;
System.out.println(num1 + " - " + num2 + " = ");
break;
case 2:
result = num1 * num2;
System.out.println(num1 + " * " + num2 + " = ");
break;
case 3:
if (num2 == 0) {
num2 = 1;
}
result = num1 / num2;
System.out.println(num1 + " / " + num2 + " = ");
break;
default:
result = 0;
}
}
}
}