10.11

package com;
import java.util.*;


public class test {
private static final String[] OPERATORS = {"+", "-", "*", "/"};
private static final int MIN_VALUE = 1;
private static final int MAX_VALUE = 50;
private static final Set<String> generatedQuestions = new HashSet<>();

public static void main(String[] args) {
generateQuestions(50);
}

public static void generateQuestions(int count) {
for (int i = 0; i < count; i++) {
String question = generateQuestion();
while (generatedQuestions.contains(question)) {
question = generateQuestion();
}
generatedQuestions.add(question);
System.out.println(question);
}
}

private static String generateQuestion() {
Random random = new Random();
int num1 = random.nextInt(MAX_VALUE - MIN_VALUE) + MIN_VALUE;
int num2 = random.nextInt(MAX_VALUE - MIN_VALUE) + MIN_VALUE;
String operator = OPERATORS[random.nextInt(OPERATORS.length)];
return num1 + " " + operator + " " + num2;
}
}
posted @ 2023-10-11 12:03  xiaolllllin  阅读(18)  评论(0编辑  收藏  举报