尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

10.14总结

10.14总结
📅 发布时间:2026/6/20 7:56:18

import java.util.*;
import java.util.concurrent.TimeUnit;

public class ArithmeticPractice {
private Set generatedQuestions = new HashSet<>();
private List questions = new ArrayList<>();
private List answers = new ArrayList<>();
private List results = new ArrayList<>();
private int totalQuestions = 30;
private int timeLimit = 5 * 60; // 5分钟,单位:秒
private Scanner scanner = new Scanner(System.in);
private boolean isTimeOut = false;

public static void main(String[] args) {ArithmeticPractice practice = new ArithmeticPractice();practice.generateQuestions();practice.startPractice();practice.showResults();
}// 生成30道不重复的题目
private void generateQuestions() {System.out.println("正在生成" + totalQuestions + "道题目...");while (questions.size() < totalQuestions) {int num1 = (int) (Math.random() * 100);int num2 = (int) (Math.random() * 100);int operator = (int) (Math.random() * 4); // 0:+,1:-,2:*,3:/String opSymbol = "";int result = 0;boolean valid = true;switch (operator) {case 0: // 加法opSymbol = "+";result = num1 + num2;break;case 1: // 减法,确保结果非负opSymbol = "-";if (num1 < num2) {valid = false;} else {result = num1 - num2;}break;case 2: // 乘法,确保结果不超过三位数opSymbol = "*";result = num1 * num2;if (result >= 1000) {valid = false;}break;case 3: // 除法,确保能整除且除数不为0opSymbol = "/";if (num2 == 0 || num1 % num2 != 0) {valid = false;} else {result = num1 / num2;}break;}// 检查题目是否有效且不重复String question = num1 + " " + opSymbol + " " + num2 + " = ?";if (valid && !generatedQuestions.contains(question)) {generatedQuestions.add(question);questions.add(question);answers.add(result);}}System.out.println("题目生成完毕,准备开始答题!");
}// 开始答题
private void startPractice() {System.out.println("\n答题开始!您有" + timeLimit/60 + "分钟时间完成" + totalQuestions + "道题。");System.out.println("请输入答案,然后按回车确认。");long startTime = System.currentTimeMillis();Thread timerThread = new Thread(new TimerRunnable(startTime));timerThread.start();for (int i = 0; i < totalQuestions; i++) {// 检查是否超时if (System.currentTimeMillis() - startTime > timeLimit * 1000L) {System.out.println("\n时间到!未完成的题目将视为错误。");isTimeOut = true;// 剩余题目标记为错误for (int j = i; j < totalQuestions; j++) {results.add(false);}break;}// 显示当前题目并获取答案System.out.print("\n第" + (i + 1) + "题: " + questions.get(i));try {if (scanner.hasNextInt()) {int userAnswer = scanner.nextInt();boolean isCorrect = (userAnswer == answers.get(i));results.add(isCorrect);// 即时判断并显示结果if (isCorrect) {System.out.println("正确!");} else {System.out.println("错误!正确答案是:" + answers.get(i));}} else {// 非数字输入视为错误scanner.next(); // 清除无效输入results.add(false);System.out.println("输入无效!正确答案是:" + answers.get(i));}} catch (Exception e) {results.add(false);System.out.println("输入错误!正确答案是:" + answers.get(i));}}// 中断计时线程timerThread.interrupt();
}// 显示答题结果
private void showResults() {int correctCount = 0;double accuracy = (double) correctCount / totalQuestions * 100;System.out.println("\n总题数: " + totalQuestions);System.out.println("做对: " + correctCount + "题");System.out.println("做错: " + (totalQuestions - correctCount) + "题");System.out.printf("正确率: %.2f%%\n", accuracy);System.out.println("------------------------------");
}// 倒计时线程
private class TimerRunnable implements Runnable {private long startTime;public TimerRunnable(long startTime) {this.startTime = startTime;}@Overridepublic void run() {try {while (true) {long elapsedTime = (System.currentTimeMillis() - startTime) / 1000;long remainingTime = timeLimit - elapsedTime;if (remainingTime <= 0) {break;}// 每分钟提示一次剩余时间if (remainingTime % 60 == 0) {System.out.println("\n剩余时间: " + remainingTime / 60 + "分" + remainingTime % 60 + "秒");}// 最后10秒每秒提示if (remainingTime <= 10) {System.out.println("\n剩余时间: " + remainingTime + "秒");}TimeUnit.SECONDS.sleep(1);}} catch (InterruptedException e) {// 线程被中断,正常退出}}
}

}

相关新闻

  • 图形学中的变换
  • 使用DirectX绘制天空盒并实现破坏和放置方块
  • DirectX12初始化

最新新闻

  • 2026 年 6 月最新腕表干货!万国全大陆官方正规维修门店地址完整公示,全国统一售后热线同步全新上线 - 万国中国服务中心
  • 天津名包回收机构实地测评:5家店报价服务全方位对比,看完再卖! - 讯息早知道
  • 2026年6月最新劳力士中国官方售后热线服务电话客户地址网点 - 劳力士服务中心
  • 2026年大平层装修深度测评:如何为你的改善型住宅匹配最佳方案? - 速递信息
  • ARM Cortex-M4微控制器架构解析:从内核到低功耗设计实战
  • 肇庆黄金回收实测六家靠谱老店盘点 - 余生黄金回收

日新闻

  • 信任的进化:技术实现详解——如何用JavaScript构建博弈论模拟器
  • Terrakube自定义工作流:如何集成OPA、Infracost等工具扩展IaC能力
  • grunt-concurrent快速入门:5分钟学会并行运行Grunt任务

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号