标签:mic image code nbsp mamicode floor 技术 png ram
1、jiemian.jsp:设置题目数量和格式
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>设置</title>
</head>
<body text="black" style="background: url(img/mai1.jpeg);background-size:100%">
<form action="yunsuan.jsp" method="get"/>
<form action="jiaoyan.jsp" method="get"/>
<div align="center" valign="center">
<div style="background-color: white">
出题数目<input type="text" name="number" id="number"/>
</div>
<div style="background-color: white">
每行数目<input type="text" name="num" id="num"/>
</div>
<input type="submit" value="提交"/>
</div>
</body>
</html>
2、yunduan.jsp:出题
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <body text="black" style="background: url(img/mai2.jpeg);background-size:100%"> <% int x = Integer.parseInt(request.getParameter("number")); int y = Integer.parseInt(request.getParameter("num")); String suanshi[]=new String[x]; int sum[]=new int[x]; int w=0; for(int i=0;i<x;i++) { int n1=(int)Math.floor(Math.random()*100+1); int n2=(int)Math.floor(Math.random()*100+1); String fuhao[]=new String[4]; int f=(int)Math.floor(Math.random()*4+1); if(f==1) { suanshi[i]=n1+"+"+n2+"="; sum[i]=n1+n2; } else if(f==2) { if(n1>n2) { suanshi[i]=n1+"-"+n2+"="; sum[i]=n1-n2; } else { suanshi[i]=n2+"-"+n1+"="; sum[i]=n2-n1; } } else if(f==3) { suanshi[i]=n1+"*"+n2+"="; sum[i]=n1*n2; } else if(f==4) { if(n2!=0) { suanshi[i]=n1+"/"+n2+"="; sum[i]=n1/n2; } else { suanshi[i]=n2+"/"+n1+"="; sum[i]=n2/n1; } } if((i+1)%y==0) { w++; System.out.println(); } } %> <title>出题</title> </head> <body> <form action="jiaoyan.jsp"/> <table> <% for(int i=0;i<w;i++) {%> <tr> <% for(int h=i*(y-1);h<=i*(y-1)+y-1;h++){ %> <td><%=suanshi[h] %></td> <td><input type="text" name="sdaan" /></td> <td><input type="hidden" name="zdaan" width="40px" value=<%=sum[h] %>></td> <%}%> </tr> <tr> <% }if(w*y<x) { for(int j=w*y;j<x;j++) {%> <td><%=suanshi[j] %></td> <td><input type="text" name="sdaan" id="sdaan"/></td> <td><input type="hidden" name="zdaan" id="zdaan" value=<%=sum[j] %>></td> <%}} %> </tr> <tr> <td> <input type="submit" value="提交"/> </td> </tr> </table> </body> </html>
3、jiaoyan.jsp:判断答案是否正确并输出正确答案
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>校对答案</title> </head> <body text="black" style="background: url(img/mai3.jpeg);background-size:100%"> <% int z=0; int c=0; String sdaan[]=request.getParameterValues("sdaan"); String zdaan[]=request.getParameterValues("zdaan"); for(int i=0;i<sdaan.length;i++) { if(sdaan[i].equals(zdaan[i])) { z++;%> <p>第<%=i+1 %>正确</p> <% } else { c++;%> <p>第<%=i+1 %>不正确,输入为<%=sdaan[i]%>,正确答案是<%=zdaan[i] %></p> <% } } %> <p>你答对了<%=z %>道题,答错了<%=c %>道题</p> <form action="shu01.jsp"></form> <input type="submit" value="重新答题"/> </body> </html>
运行截图:
标签:mic image code nbsp mamicode floor 技术 png ram
原文地址:https://www.cnblogs.com/xjmm/p/11822970.html