要口算题,那就写个吧。。。
/**
* 生成20以内的加减口算题
*/
private static void generateMental() {
Random ra = new Random();
int count = 0;
while (count < 100) {
int firstSymbol = ra.nextInt(2) % 2;
String fs = "";
int secondSymbol = ra.nextInt(2) % 2;
String ss = "";
int first = ra.nextInt(20);
int second = ra.nextInt(20);
int third = ra.nextInt(20);
if (first == 0 || second == 0 || third == 0) {
continue;
}
int result = 0;
if (firstSymbol == 1) {
fs = " + ";
result = first + second;
if (result > 20) {
continue;
}
} else {
fs = " - ";
result = first - second;
if (result < 0) {
continue;
}
}
if (secondSymbol == 1) {
ss = " + ";
result = result + third;
} else {
ss = " - ";
result = result - third;
}
if (result > 0 && result < 20 ) {
System.out.println(first + fs + second + ss + third + " = ");
count ++;
}
if (count % 25 == 0) {
System.out.println("========" + count / 25 + "=========");
}
}
}