<%@ page language="java" contentType="text/html; charset=utf8" pageEncoding="utf8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>四则运算</title> <body> <table width="500" border="0"> <tr> <td align="center" colspan="2" style="background-color:#FFA500;"> <head>四则运算</head> </td> </tr> <tr> <td> <form action="request.jsp" mehod="post"> 请输入题目数量:<input id="demo" type="test" name="num"><br /> </form> </td> </tr> </table> <script > function myFunction(){ var x=document.getElementByld("demo").value; if(x==""||lisNaN(x)){ alert("输入错误,请重新输入"); } } </script> </body> </html>
<%@ page language="java" contentType="text/html; charset=utf8" pageEncoding="utf8"%> <%@ page import="java.util.*" %> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>获取参数</title> </head> <body background="C:\Users\admin\Pictures\Saved Pictures\1.jpg" style="color:white"> <form action="judge.jsp" method="post" > <p > <% int num=Integer.parseInt(request.getParameter("num")); int[] result=new int[num]; int[] re=new int[num]; for(int i=0;i<num;i++){ Random random=new Random(); int fuhao=Math.abs(random.nextInt()%4); int a=Math.abs(random.nextInt()%(num-1))+1; int b=Math.abs(random.nextInt()%(num-1))+1; if(fuhao==0){ result[i]=a+b; out.println(a+"+"+b+"="); } if(fuhao==1){ if(a>=b){ result[i]=a-b; out.println(a+"-"+b+"="); } else{ result[i]=b-a; out.println(b+"-"+a+"="); } } if(fuhao==2){ result[i]=a*b; out.println(a+"*"+b+"="); } if(fuhao==3){ if(a%b!=0) {i--;continue;} if(b==0) {i--;continue;} else{ result[i]=a/b; out.println(a+"/"+b+"="); } } %> <input type="text" name=<%=i%>><br> </p> <% } session.setAttribute("v1",re); session.setAttribute("v2",result); session.setAttribute("v3",num); %> <input type="submit" name="submit" value="submit" > </form> </body> </html>
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%> <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>结果</title> </head> <body> <% int[] k=(int [])session.getAttribute("v2"); int n=(Integer)session.getAttribute("v3"); int []s=new int [n]; for(int i=0;i<n;i++){ s[i]=Integer.parseInt(request.getParameter(i+"")); } int right=0; for(int i=0;i<n;i++){ out.println(i+1+":"); if(s[i]==k[i]){ out.print("right"); right++; } else out.print("false"); out.print("<br>"); } %> <input type="button" value="关闭" onClick="window.close();"> </body> </html>