求大佬帮忙写个 小学算术题

xing4065285 2018-06-19 02:23:59
跪求大佬帮忙写一下,应不会很难写。已上图
...全文
539 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
stacksoverflow 2018-06-19
  • 打赏
  • 举报
回复
好吧,当我没说。
hongming09 2018-06-19
  • 打赏
  • 举报
回复
package my.test.testCall2; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Date; public class Test4 { private static BufferedReader br; public static void main(String[] args) { InputStreamReader isr = new InputStreamReader(System.in); br = new BufferedReader(isr); int count; int score; while(true){ try { while(true){ System.out.println("选择答题数 10 20 50"); String s = readConsole(); if("10".equals(s)){ count = 1; break; }else if("20".equals(s)){ count = 20; break; }else if("50".equals(s)){ count = 50; break; } System.out.println("输入有误"); } long time = new Date().getTime(); score = 0; for(int i=0;i< count;i++){ int answer = outQuestion(); System.out.print("请输入答案"); String s = readConsole(); if(String.valueOf(answer).equals(s)){ score+=1; } } time = new Date().getTime()-time; int min = (int) Math.round(time/60000-0.5); int sec = Math.round(time%60000/1000); System.out.println("答对" + score + "题 共" + count + "题 用时" +min +"分" + sec+"秒"); System.out.println("继续答题?y继续 其他退出"); if(!"y".equals(readConsole())){ break; } } catch (IOException e) { System.out.println("系统错误 重新答题"); } } } private static String readConsole() throws IOException { return br.readLine(); } private static int outQuestion() throws IOException { int op = (int) Math.round(Math.random() * 4 - 0.5); int left = (int) Math.round(Math.random() * 100 - 0.5); int right = (int) Math.round(Math.random() * 100 - 0.5); if (op == 0) { System.out.println("" + (Math.max(left, right) - Math.min(left, right)) + " + " + Math.min(left, right)); return ((Math.max(left, right) - Math.min(left, right)) + Math.min(left, right)); } else if (op == 1) { System.out.println("" + Math.max(left, right) + " - " + Math.min(left, right)); return (Math.max(left, right) - Math.min(left, right)); } else if (op == 2) { System.out.println("" + Math.max(Math.round(left / 10), 1) + " × " + Math.max(Math.round(right / 10), 1)); return (Math.max(Math.round(left / 10), 1) * Math.max(Math.round(right / 10), 1)); } else { System.out.println("" + Math.max(Math.round(left / 10), 1) * Math.max(Math.round(right / 10), 1) + " ÷ " + Math.max(Math.round(left / 10), 1)); return (Math.max(Math.round(left / 10), 1) * Math.max(Math.round(right / 10), 1) / Math.max(Math.round(left / 10), 1)); } } }
maradona1984 2018-06-19
  • 打赏
  • 举报
回复
不难,但不可能有人替你写,这个提供思路自己写 算术题就用最简单的两个数字加运算符号,控制答案在100之内是限制,加减乘除的限制都不一样(加法不能超过100,减法不能有负数,除法不能除以0,小数也最好是有理数,乘法不要超过100) 等等
hongming09 2018-06-19
  • 打赏
  • 举报
回复
漏了句
引用 6 楼 hongming09 的回复:
html的。 ====================== <!DOCTYPE HTML> <html> <head> <title>Untitled</title> </head> <body> <div> 题目数:<select id="count" onchange="countChange()"> <options> <option value="">选择出题数</option> <option value="10">10题</option> <option value="20">20题</option> <option value="50">50题</option> </options> </select> </div> <div > <ol id="questionDiv"> </ol> </div> <div > <input type="button" id="submit" value="交卷" onclick="doSubmit()"></input> <input type="button" id="re" value="重新答题" onclick="re()"></input> </div> <div id="score"> </div> <script type="text/javascript"> var qDiv = document.getElementById("questionDiv"); var cSelect = document.getElementById("count"); var startTime; function countChange(){ var html=""; for(var i=0;i<event.target.value;i++){ var op = Math.round(Math.random()*4-0.5); var left = Math.round(Math.random()*100-0.5); var right = Math.round(Math.random()*100-0.5); if(op==0){ html +="<li>" + (Math.max(left,right) - Math.min(left,right)) + " + "+ Math.min(left,right) + " = <input type='text' name='q'></input><input type='hidden' name='a' value='" + ((Math.max(left,right) - Math.min(left,right)) + Math.min(left,right)) +"'></input></li>"; }else if(op==1){ html +="<li>" + Math.max(left,right) + " - "+ Math.min(left,right) + " = <input type='text' name='q'></input><input type='hidden'name='a' value='" + (Math.max(left,right) - Math.min(left,right)) +"'></input></li>"; }else if(op==2){ html +="<li>" + Math.max(Math.round(left/10),1) + " × " + Math.max(Math.round(right/10),1) + " = <input type='text' name='q'></input><input type='hidden' name='a' value='" + (Math.max(Math.round(left/10),1) * Math.max(Math.round(right/10),1)) +"'></input></li>"; }else if(op==3){ html +="<li>" + Math.max(Math.round(left/10),1) * Math.max(Math.round(right/10),1) + " ÷ " + Math.max(Math.round(left/10),1) + " = <input type='text' name='q'></input><input type='hidden' name='a' value='" + (Math.max(Math.round(left/10),1) * Math.max(Math.round(right/10),1) / Math.max(Math.round(left/10),1)) +"'></input></li>"; } } qDiv.innerHTML=html; startTime = new Date().getTime(); } function doSubmit(){ var q = document.getElementsByName("q"),a=document.getElementsByName("a"); var score = 0; var scoreA = 100/cSelect.value for(var i =0;i<q.length;i++){ if(q[i].value==a[i].value){ score +=scoreA; } } var time = Math.round((new Date().getTime() - startTime)/60000-0.5); var time2 = Math.round((new Date().getTime() - startTime)%60000/1000); if(score == 100){ alert("恭喜用时:" + time + "分" + time2 + "秒全部答对"); }else{ alert("用时:" + time + "分" + time2 + "秒\n得分:" +score ); } } function re(){ qDiv.innerHTML=""; cSelect.value= ""; } </script> </body> </html>
hongming09 2018-06-19
  • 打赏
  • 举报
回复
html的。 ====================== <!DOCTYPE HTML> <html> <head> <title>Untitled</title> </head> <body> <div> 题目数:<select id="count" onchange="countChange()"> <options> <option value="">选择出题数</option> <option value="10">10题</option> <option value="20">20题</option> <option value="50">50题</option> </options> </select> </div> <div > <ol id="questionDiv"> </ol> </div> <div > <input type="button" id="submit" value="交卷" onclick="doSubmit()"></input> <input type="button" id="re" value="重新答题" onclick="re()"></input> </div> <div id="score"> </div> <script type="text/javascript"> var qDiv = document.getElementById("questionDiv"); var cSelect = document.getElementById("count"); var startTime; function countChange(){ var html=""; for(var i=0;i<event.target.value;i++){ var op = Math.round(Math.random()*4-0.5); var left = Math.round(Math.random()*100-0.5); var right = Math.round(Math.random()*100-0.5); if(op==0){ html +="<li>" + (Math.max(left,right) - Math.min(left,right)) + " + "+ Math.min(left,right) + " = <input type='text' name='q'></input><input type='hidden' name='a' value='" + ((Math.max(left,right) - Math.min(left,right)) + Math.min(left,right)) +"'></input></li>"; }else if(op==1){ html +="<li>" + Math.max(left,right) + " - "+ Math.min(left,right) + " = <input type='text' name='q'></input><input type='hidden'name='a' value='" + (Math.max(left,right) - Math.min(left,right)) +"'></input></li>"; }else if(op==2){ html +="<li>" + Math.max(Math.round(left/10),1) + " × " + Math.max(Math.round(right/10),1) + " = <input type='text' name='q'></input><input type='hidden' name='a' value='" + (Math.max(Math.round(left/10),1) * Math.max(Math.round(right/10),1)) +"'></input></li>"; }else if(op==3){ html +="<li>" + Math.max(Math.round(left/10),1) * Math.max(Math.round(right/10),1) + " ÷ " + Math.max(Math.round(left/10),1) + " = <input type='text' name='q'></input><input type='hidden' name='a' value='" + (Math.max(Math.round(left/10),1) * Math.max(Math.round(right/10),1) / Math.max(Math.round(left/10),1)) +"'></input></li>"; } } qDiv.innerHTML=html; startTime = new Date().getTime(); } function doSubmit(){ var q = document.getElementsByName("q"),a=document.getElementsByName("a"); var score = 0; var scoreA = 100/cSelect.value for(var i =0;i<q.length;i++){ if(q[i].value==a[i].value){ score +=scoreA; } } var time = Math.round((new Date().getTime() - startTime)/60000-0.5); var time2 = Math.round((new Date().getTime() - startTime)%60000/1000); if(score == 100){ alert("恭喜用时:" + time + "分" + time2 + "秒全部答对"); }else{ alert("用时:" + time + "分" + time2 + "秒\n得分:" +score ); } } </script> </body> </html>
Braska 2018-06-19
  • 打赏
  • 举报
回复
引用 4 楼 hjgzj 的回复:
给你个思路吧 1、首先随机生成加减乘除其中的一个符号(查查怎么随机) 2、随机生成两个数字,用上面的符号拼接 3、程序检查下计算结果是否符合范围,不符合就重新随生成两个数字,符合范围就打印输出,等做题的人录入。 4、计算的结果范围:0-100,不能包含小数,除数不能为0等等
直接随机生成加数和结果,这样就可以不用判断重新生成。
  • 打赏
  • 举报
回复
给你个思路吧 1、首先随机生成加减乘除其中的一个符号(查查怎么随机) 2、随机生成两个数字,用上面的符号拼接 3、程序检查下计算结果是否符合范围,不符合就重新随生成两个数字,符合范围就打印输出,等做题的人录入。 4、计算的结果范围:0-100,不能包含小数,除数不能为0等等
ITjavaman 2018-06-19
  • 打赏
  • 举报
回复
引用 2 楼 stacksoverflow 的回复:
打个标签,估计没人理你。
谁说的,我就给他写一个
public static void main(String []args) {
		System.out.println("这是一个小学算术运算测试程序");
	}
stacksoverflow 2018-06-19
  • 打赏
  • 举报
回复
打个标签,估计没人理你。
xing4065285 2018-06-19
  • 打赏
  • 举报
回复

50,528

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧