生成随机加减法题目

import java.util.Random;

public class Main {
    public static void main(String[] args) {
        Random rand = new Random();

        for (int i = 0; i < 20; i++) {
            int num1 = rand.nextInt(100) + 1;
            int num2 = rand.nextInt(100) + 1;
            int operator = rand.nextInt(2); // 0代表加号,1代表减号
            char operatorChar = operator == 0 ? '+' : '-';

            System.out.println(num1 + " " + operatorChar + " " + num2 + " = ");
        }
    }
}

  改进目标:

  1. 避免重复题目
  2. 可控制题目数量
  3. 增加乘除法
posted @ 2023-09-12 10:24  KALWOP  阅读(7)  评论(0编辑  收藏  举报