java web write four operations

First, to draw up a table

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<Title> four arithmetic </ title>
</head>
<form name="a1" action="chuti.jsp" onsubmit="return check(a1);">
    <H2 align = "center"> four operations </ h2>
    <table align="center"border="2" width="400">
<body>
   <tr>
    <Td> the number of items you want </ td>
    <td><input type="text" name="number" value=""placeholder="题数"
    onchange="checkti(a1)"></td>
    </tr>
    <tr>
    <Td> The number of each line you want topic </ td>
    <td><input type="text" name="hang" value=""placeholder="行数"
    onchange="checkhang(a1)"></td>
    </tr>
    <tr>
       <td colspan="2" align="center"><input type="submit" value="提交"></td>
       </tr>
       </table>
 <script type="text/javascript">
      function check(a1)
      {
    	  var num = a1.number.value;
    	  was hung = a1.hang.value;
    	  if(num.length==0)
    		  {
    		  alert ( "title number can not be empty");
    		  a1.number.value="";
    		  a1.number.focus();
    		  return false;
    		  }
    	  if(num.length==0)
		  {
		  alert ( "number of rows can not be blank");
		  a1.number.value="";
		  a1.number.focus();
		  return false;
		  }
      }
      function checkti(a1)
      {
          var num = a1.number.value;
          if(num=="")
          {
              alert ( "title number can not be empty");
              a1.number.value="";
              a1.number.focus();
              return false;
          }
      }
      function checkhang(a1)
      {
          was hung = a1.hang.value;
          if(hang.length==0)
          {
              alert ( "number of lines is not empty");
              a1.hang.value="";
              a1.hang.focus();
              return false;
          }

  Which use script statements script judge to judge you lose the initial value coming

      Then I made a topic and interface

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<Title> clicker interface </ title>
</head>
    <%
      int h=Integer.parseInt(request.getParameter("hang"));
      int n=Integer.parseInt(request.getParameter("number"));
      String value[]=new String[n];
      String answer[]=new String[n];
      int i;
      for(i=0;i<n;)
      {
          int num1=(int)(1+(Math.random()*100));
         
          int num2=(int)(1+(Math.random()*100));
          int f=(int)(1+(Math.random()*4));
          if(f==1)
          {
              value[i]=num1+"+"+num2+"=";
              answer[i]=num1+num2+"";
              i++;
          }
          else if(f==2&&num1>=num2)
          {
              value[i]=num1+"-"+num2+"=";
              answer[i]=num1-num2+"";
              i++;
          }
          else if(f==3&&num1*num2<100)
          {
              value[i]=num1+"*"+num2+"=";
              answer[i]=num1*num2+"";
              i++;
          }
          else if(f==4&&num2!=0&&num1%num2==0)
          {
              value[i]=num1+"/"+num2+"=";
              answer[i]=num1/num2+"";
              i++;
          }
          else
              continue;
      }
      %>
<body>
<H2 align = "center"> exercises </ h2>
    <form action="panduan.jsp">
    <table align="center"border="2" width="400">
        <%
        int k;
        for(int j=0;j<n;)
        {
            k=0;
            %>
            <tr>
            <%
            while(k<h)
            {
            %>
                <td><%=value[j] %></td>
                <td><input type="hidden" name="value" value=<%=value[j] %>></td>
                   <td><input type="text" name="result" /></td>
                   <td><input type="hidden" name="answer" value=<%=answer[j] %>></td>
            <%
            j++;
            k++;
            if(j>=n)
                break;
            }
            %>
            </tr>
            <%
        }
        %>
        <tr>
            <td colspan="2" align="center"><input type="submit" value="提交"></td>
        </tr>
    </table>
    </form>
     
</body>
</html>

  And then design a background to judge the program

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<Title> clicker interface </ title>
</head>
    <%
      int h=Integer.parseInt(request.getParameter("hang"));
      int n=Integer.parseInt(request.getParameter("number"));
      String value[]=new String[n];
      String answer[]=new String[n];
      int i;
      for(i=0;i<n;)
      {
          int num1=(int)(1+(Math.random()*100));
         
          int num2=(int)(1+(Math.random()*100));
          int f=(int)(1+(Math.random()*4));
          if(f==1)
          {
              value[i]=num1+"+"+num2+"=";
              answer[i]=num1+num2+"";
              i++;
          }
          else if(f==2&&num1>=num2)
          {
              value[i]=num1+"-"+num2+"=";
              answer[i]=num1-num2+"";
              i++;
          }
          else if(f==3&&num1*num2<100)
          {
              value[i]=num1+"*"+num2+"=";
              answer[i]=num1*num2+"";
              i++;
          }
          else if(f==4&&num2!=0&&num1%num2==0)
          {
              value[i]=num1+"/"+num2+"=";
              answer[i]=num1/num2+"";
              i++;
          }
          else
              continue;
      }
      %>
<body>
<H2 align = "center"> exercises </ h2>
    <form action="panduan.jsp">
    <table align="center"border="2" width="400">
        <%
        int k;
        for(int j=0;j<n;)
        {
            k=0;
            %>
            <tr>
            <%
            while(k<h)
            {
            %>
                <td><%=value[j] %></td>
                <td><input type="hidden" name="value" value=<%=value[j] %>></td>
                   <td><input type="text" name="result" /></td>
                   <td><input type="hidden" name="answer" value=<%=answer[j] %>></td>
            <%
            j++;
            k++;
            if(j>=n)
                break;
            }
            %>
            </tr>
            <%
        }
        %>
        <tr>
            <td colspan="2" align="center"><input type="submit" value="提交"></td>
        </tr>
    </table>
    </form>
     
</body>
</html>

  The last end interface

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<Title> End Interface </ title>
</head>
<body>
     The answer ends
</body>
</html>

  

 

 

 

Guess you like

Origin www.cnblogs.com/sunhongbin/p/11762737.html