姑姑带着妹妹来我家玩,让我给孩子出点口算题,我当仁不让,直接出了1000题给妹妹做。
效果如下,内容存在了txt中。
下面是代码,只需要改几个变量就能改出题的量和难度。
/**
* @version 1.0
* @author: Pig One
* @date: 2022/8/1 10:46
* @decription: 出几条10以内的加减法给孩子做做
*/
public class Arg_10 {
//做10以内的加减法,两个加起来不超过十
final static int MAX_SUM = 10;
//一天昨天20道题题
final static int DAY_TASKS = 20;
//一共多少天的量
final static int DAYS = 50;
public static void main(String[] args) {
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("/Users/zhuyi/IdeaProjects/Spirng5Learn/demo01/src/com/zy/LCSummer/task.txt")));
BufferedWriter writerRes = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("/Users/zhuyi/IdeaProjects/Spirng5Learn/demo01/src/com/zy/LCSummer/res.txt")));
for (int i = 0; i < DAY_TASKS * DAYS; i++) {
int a = new Random().nextInt(MAX_SUM);
int b = new Random().nextInt(MAX_SUM);
//两数之和大于10且不为0
while ((a + b) > MAX_SUM || a == 0 || b == 0) {
a = new Random().nextInt(MAX_SUM);
b = new Random().nextInt(MAX_SUM);
}
if (i == 0) {
writer.write("口算 1000题");
writerRes.write("口算 1000题 答案");
}
if (i % DAY_TASKS == 0) {
writer.write("\n\n");
writerRes.write("\n\n");
writer.write("day " + (i / DAY_TASKS + 1));
writerRes.write("day " + (i / DAY_TASKS + 1) + " answer");
writer.newLine();
writerRes.newLine();
}
String task = (i % DAY_TASKS + 1) + ": " + a + " + " + b + " = ? ";
String res = (i % DAY_TASKS + 1) + ": " + (a + b);
writer.write(task);
writer.newLine();
writerRes.write(res);
writerRes.newLine();
}
// System.out.println(a+ "+" +b +"=?");
writer.flush();
writer.close();
writerRes.flush();
writerRes.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
快去折磨孩子吧!
对了,如果有小数,需要加一点判断把a、b变成浮点数。
妹妹:听我说谢谢你。