zoukankan      html  css  js  c++  java
  • Javaweb版四则运算

    显示出题界面shu01.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    
    <title>Insert title here</title>
    </head>
    <body text="black"  style="background: url(img/abc.jpg);background-size:100%">
    <form action="shu02.jsp" method="get"/>
    <form action="shu03.jsp" method="get"/>
    <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="提交"/>
    </body>
    </html>

    出题界面shu02.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/timg2RFSY8VY.jpg);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="shu03.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"  value=<%=sum[h] %>></td>
    <%}%>
    
    </tr>
    
    <%
    }if(w*y<x)
        { for(int j=w*y;j<x;j++)
        {%>
        <tr>
    <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>

    结果进行比较核对界面 shu03.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/timgQUBYDDDI.jpg);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>

     

     开始的时候没有思路,就在网上找了代码,看看了怎么在里面插入代码,怎么进行界面跳转,怎么进行数据在不同界面的传递,通过这一道题,学会了很多;

  • 相关阅读:
    正则表达式在行首添加指定内容
    linux之find命令详解
    一次安装rpcbind失败引发的思考
    配置linux实现路由功能
    chkconfig命令详解
    1225 数数字
    蛇形填数 ------- 模拟水题
    开灯问题---------简单模拟
    单源最短路径
    图的表示方式
  • 原文地址:https://www.cnblogs.com/1234yyf/p/11818276.html
Copyright © 2011-2022 走看看