parent
9130049f07
commit
0a6bccedf5
Binary file not shown.
@ -0,0 +1,70 @@
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
public class KouSuanTiKa {
|
||||
private static final int PROBLEMS_PER_ROW = 5;
|
||||
private static final int ROWS = 100;
|
||||
|
||||
public static void main(String[] args) {
|
||||
try (Workbook workbook = new XSSFWorkbook()) {
|
||||
// 创建加法工作表
|
||||
createAdditionWorksheet(workbook);
|
||||
// 创建减法工作表
|
||||
createSubtractionWorksheet(workbook);
|
||||
|
||||
// 保存文件
|
||||
try (FileOutputStream fileOut = new FileOutputStream("c:/math_worksheets.xlsx")) {
|
||||
workbook.write(fileOut);
|
||||
}
|
||||
System.out.println("口算题卡已生成完成!");
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void createAdditionWorksheet(Workbook workbook) {
|
||||
Sheet sheet = workbook.createSheet("加法口算题");
|
||||
Random random = new Random();
|
||||
|
||||
// 设置列宽
|
||||
for (int i = 0; i < PROBLEMS_PER_ROW; i++) {
|
||||
sheet.setColumnWidth(i, 15 * 256);
|
||||
}
|
||||
|
||||
// 生成题目
|
||||
for (int i = 0; i < ROWS; i++) {
|
||||
Row row = sheet.createRow(i);
|
||||
for (int j = 0; j < PROBLEMS_PER_ROW; j++) {
|
||||
int num1 = random.nextInt(20) + 1;
|
||||
int num2 = random.nextInt(20) + 1;
|
||||
Cell cell = row.createCell(j);
|
||||
cell.setCellValue(num1 + " + " + num2 + " = ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void createSubtractionWorksheet(Workbook workbook) {
|
||||
Sheet sheet = workbook.createSheet("减法口算题");
|
||||
Random random = new Random();
|
||||
|
||||
// 设置列宽
|
||||
for (int i = 0; i < PROBLEMS_PER_ROW; i++) {
|
||||
sheet.setColumnWidth(i, 15 * 256);
|
||||
}
|
||||
|
||||
// 生成题目
|
||||
for (int i = 0; i < ROWS; i++) {
|
||||
Row row = sheet.createRow(i);
|
||||
for (int j = 0; j < PROBLEMS_PER_ROW; j++) {
|
||||
int num1 = random.nextInt(10) + 1;
|
||||
int num2 = random.nextInt(num1) + 1; // 确保结果为正数
|
||||
Cell cell = row.createCell(j);
|
||||
cell.setCellValue(num1 + " - " + num2 + " = ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue