9月23
今天完成了课后第一题:
随机生成三十道四则运算题
import java.util.Random;
public class ArithmeticQuizGenerator {
private static final char[] OPERATORS = {'+', '-', '*', '/'};
public static void main(String[] args) {
Random random = new Random();
for (int i = 0; i < 30; i++) {
int num1 = random.nextInt(100) + 1;
int num2 = random.nextInt(100) + 1;
char operator = OPERATORS[random.nextInt(OPERATORS.length)];
if (operator == '/' && num2 == 0) {
num2 = 1;
}
System.out.println(num1 + " " + operator + " " + num2 + " = ?");
}
}
}