• 四则运算完整版


    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/19.jpg);
    }
    </style>
    </head>
    <body>
    <%
    try
    {
        int tishu=Integer.parseInt(request.getParameter("geshu"));
        int fanwei=Integer.parseInt(request.getParameter("fanwei"));
        session.setAttribute("tishu", tishu);
        session.setAttribute("fanwei", fanwei);
        response.setHeader("refresh","0;url = zhengshu.jsp");
    }
    catch(Exception e)
    {
        %>
        <script type="text/javascript">
        alert("输入错误,点击确定返回重新输入!!!")
        </script>
        <%
        response.setHeader("refresh","0;url = error.jsp");
    }
    %>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/7.jpg);
    }
    </style>
    </head>
    <body>
    <form id="form2" name="form2" method="post" action="chaundi.jsp">
    <div style="text-align:center;color:#F09">
    <br>
        <br>
        <br>
        <br>
        <br>
        <br>
    请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
    请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
    <input name="" type="submit" value="提交" />
    </div>
    </form>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/19.jpg);
    }
    </style>
    </head>
    <body>
    <%
    try
    {
        int tishu=Integer.parseInt(request.getParameter("geshu"));
        int fanwei=Integer.parseInt(request.getParameter("fanwei"));
        session.setAttribute("tishu", tishu);
        session.setAttribute("fanwei", fanwei);
        response.setHeader("refresh","0;url = fenshu.jsp");
    }
    catch(Exception e)
    {
        %>
        
        <script type="text/javascript">
        alert("输入错误,点击确定返回重新输入!!!")
        </script>
        <%
        response.setHeader("refresh","0;url = fenerror.jsp");
    }
    %>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/7.jpg);
    }
    </style>
    </head>
    <body>
    <form id="form2" name="form2" method="post" action="fenchuandi.jsp">
    <div style="text-align:center;color:#F09">
    <br>
        <br>
        <br>
        <br>
        <br>
        <br>
    请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
    请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
    <input name="" type="submit" value="提交" />
    </div>
    </form>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" import="java.util.Random"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/4.jpg);
    }
    </style>
    </head>
    <body>
    <%!
    class Suan2//真分数的运算类
    {
        public int m,n,x,y,c;//定义4个变量,还有一个符号变量
        public Random random=new Random();
        String s;//生成的计算式储存咋m里面
        int fanwei;
        public void shengcheng(int fanwei1)
        {
            fanwei=fanwei1;
            c=random.nextInt(4);
            x=random.nextInt(fanwei);
            y=random.nextInt(fanwei);
            m=random.nextInt(fanwei);
            n=random.nextInt(fanwei);//生成4个随机数在50以内,赋给x,y,m,n
            String fuhao;
            for(int i=0;;i++)
            {
                if(x==0)//不能生成0
                {
                x=random.nextInt(fanwei);
                }
                else
                {
                    break;
                }
            }
            for(int i=0;;i++)
            {
                if(y==0||y==x)//不能生成0
                {
                y=random.nextInt(fanwei);
                }
                else
                {
                    break;
                }
            }
            for(int i=0;;i++)
            {
                if(m==0)//不能生成0
                {
                m=random.nextInt(fanwei);
                }
                else
                {
                    break;
                }
            }
            for(int i=0;;i++)
            {
                if(n==0||m==n)//不能生成0
                {
                n=random.nextInt(fanwei);
                }
                else
                {
                    break;
                }
            }
            if(c==0)//通整数一样,0是加法,1减法,2乘法,3除法
             {
                 fuhao="+";
             }
             else if(c==1)
             {
                 fuhao="-";
             }
             else if(c==2)
             {
                 fuhao="*";
             }
             else
             {
                 fuhao="/";
             }
            int gongyue=Gongyue(x,y);
            x=x/gongyue;
            y=y/gongyue;
            gongyue=Gongyue(m,n);
            m=m/gongyue;
            n=n/gongyue;
        }
        public String shuchu()//定义输出函数
        {
            if(c==0)
            {
                if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                s=y+"/"+x+"  +  "+n+"/"+m+"=";
                return jisuan(x,y,m,n,c);//返回计算结果
                }
                else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果
                {
                    s=y+"/"+x+"  +  "+m+"/"+n+"=";
                    return jisuan(x,y,n,m,c);//返回计算结果
                }
                else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                    s=x+"/"+y+"  +  "+n+"/"+m+"=";
                    return jisuan(y,x,m,n,c);//返回计算结果
                }
                else//生成的分母必须大于分子,输出不同的结果
                {
                    s=x+"/"+y+"  +  "+m+"/"+n+"=";
                    return jisuan(y,x,n,m,c);//返回计算结果
                }
            }
            else if(c==1)
            {
                double x1=Double.parseDouble(String.valueOf(x));
                double y1=Double.parseDouble(String.valueOf(y));
                double m1=Double.parseDouble(String.valueOf(m));
                double n1=Double.parseDouble(String.valueOf(n));    
                if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {    
                    if((y1/x1)>(n1/m1))
                    {
                        s=y+"/"+x+"  -  "+n+"/"+m+"=";
                        return jisuan(x,y,m,n,c);//返回计算结果
                    }
                    else
                    {
                        s=n+"/"+m+"  -  "+y+"/"+x+"=";
                        return jisuan(m,n,x,y,c);//返回计算结果
                    }
                }
                else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果
                {
                    if((y1/x1)>(m1/n1))//减数必须大于被减数
                    {
                        s=y+"/"+x+"  -  "+m+"/"+n+"=";
                        return jisuan(x,y,n,m,c);//返回计算结果
                    }
                    else//减数必须大于被减数
                    {
                        s=m+"/"+n+"  -  "+y+"/"+x+"=";
                        return jisuan(n,m,x,y,c);//返回计算结果
                    }
                }
                else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                    if((x1/y1)>(n1/m1))//减数必须大于被减数
                    {
                        s=x+"/"+y+"  -  "+n+"/"+m+"=";
                        return jisuan(y,x,m,n,c);
                    }
                    else//减数必须大于被减数
                    {
                        s=n+"/"+m+"  -  "+x+"/"+y+"=";
                        return jisuan(m,n,y,x,c);//返回计算结果
                    }
                }
                else
                {
                    if((x1/y1)>(m1/n1))//生成的分母必须大于分子,输出不同的结果//减数必须大于被减数
                    {
                        s=x+"/"+y+"  -  "+m+"/"+n+"=";
                        return jisuan(y,x,n,m,c);//返回计算结果
                    }
                    else//减数必须大于被减数
                    {
                        s=m+"/"+n+"  -  "+x+"/"+y+"=";
                        return jisuan(n,m,y,x,c);//返回计算结果
                    }
                }
            }
            else if(c==2)
            {
                if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                s=y+"/"+x+"  *  "+n+"/"+m+"=";
                return jisuan(x,y,m,n,c);//返回计算结果
                }
                else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果
                {
                    s=y+"/"+x+"  *  "+m+"/"+n+"=";
                    return jisuan(x,y,n,m,c);//返回计算结果
                }
                else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                    s=x+"/"+y+"  *  "+n+"/"+m+"=";
                    return jisuan(y,x,m,n,c);
                }
                else//生成的分母必须大于分子,输出不同的结果
                {
                    s=x+"/"+y+"  *  "+m+"/"+n+"=";
                    return jisuan(y,x,n,m,c);//返回计算结果
                }
            }
            else
            {
                if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                s=y+"/"+x+"  /  "+n+"/"+m+"=";
                return jisuan(x,y,m,n,c);//返回计算结果
                }
                else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果
                {
                    s=y+"/"+x+"  /  "+m+"/"+n+"=";
                    return jisuan(x,y,n,m,c);//返回计算结果
                }
                else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                    s=x+"/"+y+"  /  "+n+"/"+m+"=";
                    return jisuan(y,x,m,n,c);//返回计算结果
                }
                else//生成的分母必须大于分子,输出不同的结果
                {
                    s=x+"/"+y+"  /  "+m+"/"+n+"=";
                    return jisuan(y,x,n,m,c);//返回计算结果
                }
            }
        }
        public String jisuan(int a,int b,int c,int d,int m)//计算结果的函数
        {
            String daan;
            int gongyue,gongbei;
            if(m==0)//加法计算的结果算法
            {
                gongbei=Gongbei(a,c);//求两个分母的最小公倍数
                int s1,s2,s3;
                s1=gongbei/a;
                s2=gongbei/c;
                s3=b*s1+d*s2;
                if(s3==gongbei)
                {
                    return("1");
                }
                else
                {
                    gongyue=Gongyue(s3,gongbei);
                    int fenzi=s3/gongyue,fenmu=gongbei/gongyue;
                    if(fenzi<fenmu)
                    {
                        daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                    else
                    {
                        int zhi=fenzi/fenmu;
                        daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                }
            }
            else if(m==1)//减法计算的结果算法
            {
                gongbei=Gongbei(a,c);
                int s1,s2,s3;
                s1=gongbei/a;
                s2=gongbei/c;
                s3=b*s1-d*s2;
                if(s3==gongbei)
                {
                    return("1");
                }
                else
                {
                    if(s3==0)
                    {
                        daan=String.valueOf("0");
                        return daan;
                    }
                    else
                    {
                    gongyue=Gongyue(s3,gongbei);
                    int fenzi=s3/gongyue,fenmu=gongbei/gongyue;
                    if(fenzi<fenmu)
                    {
                        daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                    else
                    {
                        int zhi=fenzi/fenmu;
                        daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                    }
                }
            }
            else if(m==2)//乘法计算的结果算法
            {
                int s1,s2;
                s1=a*c;
                s2=b*d;
                if(s1==s2)
                {
                    return("1");
                }
                else
                {
                    gongyue=Gongyue(s1,s2);
                    int fenzi=s2/gongyue,fenmu=s1/gongyue;
                    if(fenzi<fenmu)
                    {
                        daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                    else
                    {
                        int zhi=fenzi/fenmu;
                        daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                }
            }
            else//除法计算的结果算法
            {
                int s1,s2;
                s1=a*d;
                s2=b*c;
                if(s1==s2)
                {
                    return("1");
                }
                else
                {
                    gongyue=Gongyue(s1,s2);
                    int fenzi=s2/gongyue,fenmu=s1/gongyue;
                    if(fenzi<fenmu)
                    {
                        daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                    else
                    {
                        int zhi=fenzi/fenmu;
                        daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                }
            }
        }
        public int Gongbei(int a,int c)//求最小公倍数的函数
        {
            int gongbei;
            if(a>c)
            {
                gongbei=a;//公倍数从大的开始
                while(gongbei<=a*c)
                {
                    if(gongbei%a==0&&gongbei%c==0)
                    {
                        break;
                    }
                    gongbei++;
                }
            }
            else
            {
                gongbei=c;//公倍数从大的开始
                while(gongbei<=a*c)
                {
                    if(gongbei%a==0&&gongbei%c==0)
                    {
                        break;
                    }
                    gongbei++;
                }
            }
            return gongbei;
        }
        public int Gongyue(int gongbei,int s3)//求最大公约数的函数
        {
            int i=1,gongyue=0;
            if(gongbei>s3)//公约数从1到最小的数
            {
                while(i<=s3)
                {
                    if(gongbei%i==0&&s3%i==0)
                    {
                        gongyue=i;
                    }
                    i++;
                }
                return gongyue;
            }
            else
            {
                while(i<=gongbei)
                {
                    if(gongbei%i==0&&s3%i==0)
                    {
                        gongyue=i;
                    }
                    i++;
                }
                return gongyue;
            }
        }
        public int jianyan(String a[],int l)//检验是否生成重复计算式的函数
        {
             int flag=1;
               for(int i=0;i<l;i++)
               {
                   if(s.equals(a[i]))
                   {
                      flag=0;
                      break;
                   }
               }
               return flag;
        }
    }
    Random random=new Random();
    int tishu;
    int fanwei;
    int m=0;
    String shuju[]=new String[10000]; 
    int flag=0;
    Suan2 a=new Suan2();
    String daan,daan1;
    %>
    <%
    tishu=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
    fanwei=Integer.parseInt((String.valueOf(session.getAttribute("fanwei"))));
    session.setAttribute("tishu", tishu);
    if(m<tishu)
    {
        a.shengcheng(fanwei);
        String f=a.shuchu();
        shuju[m]=a.s;
        flag=a.jianyan(shuju, m);//返回是否有重复
        if(flag==1)//如果没有就是1
        {
        if(m+1==tishu)
        {daan=a.shuchu();
        session.setAttribute("shuju", shuju[m]);
        session.setAttribute("daan", daan);
        session.setAttribute("m", m);
            %>
        <form id="form2" name="form2" method="post" action="fenshuhuoqu.jsp">
        <div style="text-align:center">
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <%out.print(m+1+"."+shuju[m]+"=");
        m=0;%>
        <br>
        <br>
        <br>
        <br>
        请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
        <input name="" type="submit" value="提交" />
        </div>
        </form>
            <%
        }
        else
        {
            daan=a.shuchu();
            session.setAttribute("shuju", shuju[m]);
            session.setAttribute("daan", daan);
            session.setAttribute("m", m);
            %>
        <form id="form2" name="form2" method="post" action="fenshuhuoqu.jsp">
        <div style="text-align:center">
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <%out.print(m+1+"."+shuju[m]+"=");%>
        <br>
        <br>
        <br>
        <br>
        请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
        <input name="" type="submit" value="下一个" />
        </div>
        </form>
            <%
            m++;
            flag=0;
        }
        
        }
        else
        {
            response.setHeader("refresh","0;url = zhengshu.jsp");
        }
    }
    %>
    </body>
    </html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" import="java.sql.Connection" import="java.sql.DriverManager"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/18.jpg);
    }
    </style>
    </head>
    <body>
    <%!
    int tishu1;
    String error="",zhengque=""; 
    %>
    <%
    try
    {
    Connection con = null; //定义一个MYSQL链接对象
    Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "20153246"); //链接本地MYSQL
    java.sql.Statement stmt; //创建声明
    stmt = con.createStatement();
    String shuju=String.valueOf(session.getAttribute("shuju"));
    String daan=String.valueOf(session.getAttribute("daan"));
    int m=Integer.parseInt(String.valueOf(session.getAttribute("m")));
    tishu1=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
    String daan1=request.getParameter("daan1");
    String sql="INSERT INTO 真分数的四则计算 (shizi,result,userresult) VALUES ('"+shuju+" = "+"','"+daan+"','"+daan1+"')";
    stmt.executeUpdate(sql);
    if(daan.equals(daan1))
    {
        zhengque=zhengque+String.valueOf(m+1)+",";
    }
    else
    {
        error=error+String.valueOf(m+1)+",";
    }
    if(m+1==tishu1)
    {
        sql="INSERT INTO Grade (zhengque,cuowu) VALUES ('"+zhengque+"','"+error+"')";
        stmt.executeUpdate(sql);             
        
        %>
       <form id="form2" name="form2" method="post" action="xuanze.html">
           <div style="text-align:center;color:#F00">
           <strong>
           <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
           <%
           out.print("正确的题目是:"+zhengque+"<br>"+"错误的题目是:"+error+"<br>"+"点击确定返回主界面"); 
            zhengque="";
        error="";  %>
           <input name="" type="submit" value="确定" />
           </strong>
           </div>
           </form>
           <%
    }
    else
    {
    response.setHeader("refresh","0;url = fenshu.jsp");
    }
    }
    catch (Exception e) 
    {
        System.out.print("MYSQL ERROR:" + e.getMessage());
    } 
    %>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" import="java.util.Random"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/4.jpg);
    }
    </style>
    </head>
    <body>
    <%!
    class Suan1//生成整数计算的类
    {
        public int x,y,c;//定义两个变量,还有一个符号变量
        public Random random=new Random();//定义随机数
        String m;//生成的计算式储存咋m里面
        int fanwei;
        public String shengcheng(int fanwei1)//自动生成数的函数
        {
             fanwei=fanwei1;
             c=random.nextInt(4);//生成符号
             String fuhao;
             x=random.nextInt(fanwei);//生成100以内的自然数
             y=random.nextInt(fanwei);
             if(c==0)//0是加法
             {
                 fuhao="+";
                 m=String.valueOf(x)+fuhao+String.valueOf(y);
                 
             }
             else if(c==1)//1是减法
             {
                 fuhao="-";
                 if(x>=y)
                 {
                     m=String.valueOf(x)+fuhao+String.valueOf(y);
                 }
                 else
                 {
                     m=String.valueOf(y)+fuhao+String.valueOf(x);
                 }
             }
             else if(c==2)
             {
                 fuhao="*";
                 m=String.valueOf(x)+fuhao+String.valueOf(y);
             }
             else
             {
                 fuhao="/";
                 for(int i=0;;i++)
                 {
                     if(y==0)
                     {
                         y=random.nextInt(fanwei);
                     }
                     else
                     {
                         break;
                     }
                 }
                 m=String.valueOf(x)+fuhao+String.valueOf(y);
             }
             return m;
             
        }
        public String shuchu()//定义输出函数
        {
            if(c==0)
            {
                return (String.valueOf(x+y));//并且返回计算的结果
            }
            else if(c==1)
            {
                if(x>=y)//将较大的数放在前面,不能出现负数
                {
                return (String.valueOf(x-y));
                }
                else
                {
                return (String.valueOf(y-x));
                }
            }
            else if(c==2)
            {
                return (String.valueOf(x*y));
            }
            else
            {
                if(x%y==0)
                {
                    return (String.valueOf(x/y));
                }
                else
                {
                    if(x>y)
                    {
                    int shang=x/y;
                    int yushu=x-y*shang;
                    return (String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y));
                    }
                    else
                    {
                    return (String.valueOf(x)+"/"+String.valueOf(y));
                    }
                }
            }
        }
        public int fanhuic()
        {
            return c;
        }
        public int jianyan(String a[],int s)//检验是否有重复的式子,如果有返回0,没有就返回1
        {
           int flag=1;
           for(int i=0;i<s;i++)
           {
               if(m.equals(a[i]))//数组a里面是生成的式子
               {
                  flag=0;
                  break;
               }
           }
           return flag;
        }
    }
    class Suan2//真分数的运算类
    {
        public int m,n,x,y,c;//定义4个变量,还有一个符号变量
        public Random random=new Random();
        String s;//生成的计算式储存咋m里面
        int fanwei;
        public void shengcheng(int fanwei1)
        {
            fanwei=fanwei1;
            c=random.nextInt(4);
            x=random.nextInt(fanwei);
            y=random.nextInt(fanwei);
            m=random.nextInt(fanwei);
            n=random.nextInt(fanwei);//生成4个随机数在50以内,赋给x,y,m,n
            String fuhao;
            for(int i=0;;i++)
            {
                if(x==0)//不能生成0
                {
                x=random.nextInt(fanwei);
                }
                else
                {
                    break;
                }
            }
            for(int i=0;;i++)
            {
                if(y==0||y==x)//不能生成0
                {
                y=random.nextInt(fanwei);
                }
                else
                {
                    break;
                }
            }
            for(int i=0;;i++)
            {
                if(m==0)//不能生成0
                {
                m=random.nextInt(fanwei);
                }
                else
                {
                    break;
                }
            }
            for(int i=0;;i++)
            {
                if(n==0||m==n)//不能生成0
                {
                n=random.nextInt(fanwei);
                }
                else
                {
                    break;
                }
            }
            if(c==0)//通整数一样,0是加法,1减法,2乘法,3除法
             {
                 fuhao="+";
             }
             else if(c==1)
             {
                 fuhao="-";
             }
             else if(c==2)
             {
                 fuhao="*";
             }
             else
             {
                 fuhao="/";
             }
            int gongyue=Gongyue(x,y);
            x=x/gongyue;
            y=y/gongyue;
            gongyue=Gongyue(m,n);
            m=m/gongyue;
            n=n/gongyue;
        }
        public String shuchu()//定义输出函数
        {
            if(c==0)
            {
                if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                s=y+"/"+x+"  +  "+n+"/"+m+"=";
                return jisuan(x,y,m,n,c);//返回计算结果
                }
                else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果
                {
                    s=y+"/"+x+"  +  "+m+"/"+n+"=";
                    return jisuan(x,y,n,m,c);//返回计算结果
                }
                else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                    s=x+"/"+y+"  +  "+n+"/"+m+"=";
                    return jisuan(y,x,m,n,c);//返回计算结果
                }
                else//生成的分母必须大于分子,输出不同的结果
                {
                    s=x+"/"+y+"  +  "+m+"/"+n+"=";
                    return jisuan(y,x,n,m,c);//返回计算结果
                }
            }
            else if(c==1)
            {
                double x1=Double.parseDouble(String.valueOf(x));
                double y1=Double.parseDouble(String.valueOf(y));
                double m1=Double.parseDouble(String.valueOf(m));
                double n1=Double.parseDouble(String.valueOf(n));    
                if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {    
                    if((y1/x1)>(n1/m1))
                    {
                        s=y+"/"+x+"  -  "+n+"/"+m+"=";
                        return jisuan(x,y,m,n,c);//返回计算结果
                    }
                    else
                    {
                        s=n+"/"+m+"  -  "+y+"/"+x+"=";
                        return jisuan(m,n,x,y,c);//返回计算结果
                    }
                }
                else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果
                {
                    if((y1/x1)>(m1/n1))//减数必须大于被减数
                    {
                        s=y+"/"+x+"  -  "+m+"/"+n+"=";
                        return jisuan(x,y,n,m,c);//返回计算结果
                    }
                    else//减数必须大于被减数
                    {
                        s=m+"/"+n+"  -  "+y+"/"+x+"=";
                        return jisuan(n,m,x,y,c);//返回计算结果
                    }
                }
                else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                    if((x1/y1)>(n1/m1))//减数必须大于被减数
                    {
                        s=x+"/"+y+"  -  "+n+"/"+m+"=";
                        return jisuan(y,x,m,n,c);
                    }
                    else//减数必须大于被减数
                    {
                        s=n+"/"+m+"  -  "+x+"/"+y+"=";
                        return jisuan(m,n,y,x,c);//返回计算结果
                    }
                }
                else
                {
                    if((x1/y1)>(m1/n1))//生成的分母必须大于分子,输出不同的结果//减数必须大于被减数
                    {
                        s=x+"/"+y+"  -  "+m+"/"+n+"=";
                        return jisuan(y,x,n,m,c);//返回计算结果
                    }
                    else//减数必须大于被减数
                    {
                        s=m+"/"+n+"  -  "+x+"/"+y+"=";
                        return jisuan(n,m,y,x,c);//返回计算结果
                    }
                }
            }
            else if(c==2)
            {
                if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                s=y+"/"+x+"  *  "+n+"/"+m+"=";
                return jisuan(x,y,m,n,c);//返回计算结果
                }
                else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果
                {
                    s=y+"/"+x+"  *  "+m+"/"+n+"=";
                    return jisuan(x,y,n,m,c);//返回计算结果
                }
                else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                    s=x+"/"+y+"  *  "+n+"/"+m+"=";
                    return jisuan(y,x,m,n,c);
                }
                else//生成的分母必须大于分子,输出不同的结果
                {
                    s=x+"/"+y+"  *  "+m+"/"+n+"=";
                    return jisuan(y,x,n,m,c);//返回计算结果
                }
            }
            else
            {
                if(x>y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                s=y+"/"+x+"  /  "+n+"/"+m+"=";
                return jisuan(x,y,m,n,c);//返回计算结果
                }
                else if(x>y&&m<n)//生成的分母必须大于分子,输出不同的结果
                {
                    s=y+"/"+x+"  /  "+m+"/"+n+"=";
                    return jisuan(x,y,n,m,c);//返回计算结果
                }
                else if(x<y&&m>n)//生成的分母必须大于分子,输出不同的结果
                {
                    s=x+"/"+y+"  /  "+n+"/"+m+"=";
                    return jisuan(y,x,m,n,c);//返回计算结果
                }
                else//生成的分母必须大于分子,输出不同的结果
                {
                    s=x+"/"+y+"  /  "+m+"/"+n+"=";
                    return jisuan(y,x,n,m,c);//返回计算结果
                }
            }
        }
        public String jisuan(int a,int b,int c,int d,int m)//计算结果的函数
        {
            String daan;
            int gongyue,gongbei;
            if(m==0)//加法计算的结果算法
            {
                gongbei=Gongbei(a,c);//求两个分母的最小公倍数
                int s1,s2,s3;
                s1=gongbei/a;
                s2=gongbei/c;
                s3=b*s1+d*s2;
                if(s3==gongbei)
                {
                    return("1");
                }
                else
                {
                    gongyue=Gongyue(s3,gongbei);
                    int fenzi=s3/gongyue,fenmu=gongbei/gongyue;
                    if(fenzi<fenmu)
                    {
                        daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                    else
                    {
                        int zhi=fenzi/fenmu;
                        daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                }
            }
            else if(m==1)//减法计算的结果算法
            {
                gongbei=Gongbei(a,c);
                int s1,s2,s3;
                s1=gongbei/a;
                s2=gongbei/c;
                s3=b*s1-d*s2;
                if(s3==gongbei)
                {
                    return("1");
                }
                else
                {
                    if(s3==0)
                    {
                        daan=String.valueOf("0");
                        return daan;
                    }
                    else
                    {
                    gongyue=Gongyue(s3,gongbei);
                    int fenzi=s3/gongyue,fenmu=gongbei/gongyue;
                    if(fenzi<fenmu)
                    {
                        daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                    else
                    {
                        int zhi=fenzi/fenmu;
                        daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                    }
                }
            }
            else if(m==2)//乘法计算的结果算法
            {
                int s1,s2;
                s1=a*c;
                s2=b*d;
                if(s1==s2)
                {
                    return("1");
                }
                else
                {
                    gongyue=Gongyue(s1,s2);
                    int fenzi=s2/gongyue,fenmu=s1/gongyue;
                    if(fenzi<fenmu)
                    {
                        daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                    else
                    {
                        int zhi=fenzi/fenmu;
                        daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                }
            }
            else//除法计算的结果算法
            {
                int s1,s2;
                s1=a*d;
                s2=b*c;
                if(s1==s2)
                {
                    return("1");
                }
                else
                {
                    gongyue=Gongyue(s1,s2);
                    int fenzi=s2/gongyue,fenmu=s1/gongyue;
                    if(fenzi<fenmu)
                    {
                        daan=String.valueOf(fenzi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                    else
                    {
                        int zhi=fenzi/fenmu;
                        daan=String.valueOf(zhi)+"‘"+String.valueOf(fenzi-fenmu*zhi)+"/"+String.valueOf(fenmu);//通分
                        return daan;
                    }
                }
            }
        }
        public int Gongbei(int a,int c)//求最小公倍数的函数
        {
            int gongbei;
            if(a>c)
            {
                gongbei=a;//公倍数从大的开始
                while(gongbei<=a*c)
                {
                    if(gongbei%a==0&&gongbei%c==0)
                    {
                        break;
                    }
                    gongbei++;
                }
            }
            else
            {
                gongbei=c;//公倍数从大的开始
                while(gongbei<=a*c)
                {
                    if(gongbei%a==0&&gongbei%c==0)
                    {
                        break;
                    }
                    gongbei++;
                }
            }
            return gongbei;
        }
        public int Gongyue(int gongbei,int s3)//求最大公约数的函数
        {
            int i=1,gongyue=0;
            if(gongbei>s3)//公约数从1到最小的数
            {
                while(i<=s3)
                {
                    if(gongbei%i==0&&s3%i==0)
                    {
                        gongyue=i;
                    }
                    i++;
                }
                return gongyue;
            }
            else
            {
                while(i<=gongbei)
                {
                    if(gongbei%i==0&&s3%i==0)
                    {
                        gongyue=i;
                    }
                    i++;
                }
                return gongyue;
            }
        }
        public int jianyan(String a[],int l)//检验是否生成重复计算式的函数
        {
             int flag=1;
               for(int i=0;i<l;i++)
               {
                   if(s.equals(a[i]))
                   {
                      flag=0;
                      break;
                   }
               }
               return flag;
        }
    }
    int tishu;
    int fanwei;
    int m=0;
    Random random=new Random();
    String shuju[]=new String[10000]; 
    int flag=0;
    Suan2 a=new Suan2();
    Suan1 b=new Suan1();
    String daan,daan1;
    %>
    <%
    tishu=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
    fanwei=Integer.parseInt((String.valueOf(session.getAttribute("fanwei"))));
    session.setAttribute("tishu", tishu);
    if(m<tishu)
    {
        int t=random.nextInt(2);
        if(t==0)
        {
            a.shengcheng(fanwei);
            String f=a.shuchu();
            shuju[m]=a.s;
            flag=a.jianyan(shuju, m);//返回是否有重复
            if(flag==1)//如果没有就是1
            {
            if(m+1==tishu)
            {daan=a.shuchu();
            session.setAttribute("shuju", shuju[m]);
            session.setAttribute("daan", daan);
            session.setAttribute("m", m);
                %>
            <form id="form2" name="form2" method="post" action="fenzhenghuoqu.jsp">
            <div style="text-align:center">
            <%out.print(m+1+"."+shuju[m]+"=");
            m=0;%>
            <br>
            <br>
            <br>
            <br>
            <br>
            请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
            <input name="" type="submit" value="提交" />
            </div>
            </form>
                <%
            }
            else
            {
                daan=a.shuchu();
                session.setAttribute("shuju", shuju[m]);
                session.setAttribute("daan", daan);
                session.setAttribute("m", m);
                %>
            <form id="form2" name="form2" method="post" action="fenzhenghuoqu.jsp">
            <div style="text-align:center">
            <%out.print(m+1+"."+shuju[m]+"=");%>
            <br>
            <br>
            <br>
            <br>
            <br>
            请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
            <input name="" type="submit" value="下一个" />
            </div>
            </form>
                <%
                m++;
                flag=0;
            }
            
            }
            else
            {
                response.setHeader("refresh","0;url = fenzheng.jsp");
            }
        }
        else
        {
            shuju[m]=b.shengcheng(fanwei);//将生成的计算式储存咋数组里面
            flag=b.jianyan(shuju, m);//返回是否有重复
            if(flag==1)//如果没有就是1
            {
            if(m+1==tishu)
            {daan=b.shuchu();
            session.setAttribute("shuju", shuju[m]);
            session.setAttribute("daan", daan);
            session.setAttribute("m", m);
                %>
            <form id="form2" name="form2" method="post" action="fenzhenghuoqu.jsp">
            <div style="text-align:center">
            <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
            <%out.print(m+1+"."+shuju[m]+"=");
            m=0;%>
            <br>
            <br>
            <br>
            <br>
            请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
            <input name="" type="submit" value="提交" />
            </div>
            </form>
                <%
            }
            else
            {
                daan=b.shuchu();
                session.setAttribute("shuju", shuju[m]);
                session.setAttribute("daan", daan);
                session.setAttribute("m", m);
                %>
            <form id="form2" name="form2" method="post" action="fenzhenghuoqu.jsp">
            <div style="text-align:center">
            <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
            <%out.print(m+1+"."+shuju[m]+"=");%>
            <br>
            <br>
            <br>
            <br>
            请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
            <input name="" type="submit" value="下一个" />
            </div>
            </form>
                <%
                m++;
                flag=0;
            }
            
            }
            else
            {
                response.setHeader("refresh","1;url = fenzheng.jsp");
            }
        }
        
    }
    %>
    
    
    
    
    
    
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    try
    {
        int tishu=Integer.parseInt(request.getParameter("geshu"));
        int fanwei=Integer.parseInt(request.getParameter("fanwei"));
        session.setAttribute("tishu", tishu);
        session.setAttribute("fanwei", fanwei);
        response.setHeader("refresh","0;url = fenzheng.jsp");
    }
    catch(Exception e)
    {
        %>
        
        <script type="text/javascript">
        alert("输入错误,点击确定返回重新输入!!!")
        </script>
        <%
        response.setHeader("refresh","0;url = fenzhengerror.jsp");
    }
    %>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/7.jpg);
    }
    </style>
    </head>
    <body>
    <form id="form2" name="form2" method="post" action="fenzhengchuangdi.jsp">
    <div style="text-align:center;color:#F09">
    <br>
        <br>
        <br>
        <br>
        <br>
        <br>
    请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
    请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
    <input name="" type="submit" value="提交" />
    </div>
    </form>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" import="java.sql.Connection" import="java.sql.DriverManager"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/18.jpg);
    }
    </style>
    </head>
    <body>
    <%!
    int tishu1;
    String error="",zhengque=""; 
    %>
    <%
    try
    {
    Connection con = null; //定义一个MYSQL链接对象
    Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "20153246"); //链接本地MYSQL
    java.sql.Statement stmt; //创建声明
    stmt = con.createStatement();
    String shuju=String.valueOf(session.getAttribute("shuju"));
    String daan=String.valueOf(session.getAttribute("daan"));
    int m=Integer.parseInt(String.valueOf(session.getAttribute("m")));
    tishu1=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
    String daan1=request.getParameter("daan1");
    String sql="INSERT INTO 整数与真分数的混合四则运算 (shizi,result,userresult) VALUES ('"+shuju+" = "+"','"+daan+"','"+daan1+"')";
    stmt.executeUpdate(sql);
    if(daan.equals(daan1))
    {
        zhengque=zhengque+String.valueOf(m+1)+",";
    }
    else
    {
        error=error+String.valueOf(m+1)+",";
    }
    if(m+1==tishu1)
    {
        sql="INSERT INTO Grade (zhengque,cuowu) VALUES ('"+zhengque+"','"+error+"')";
        stmt.executeUpdate(sql);             
        
        %>
       <form id="form2" name="form2" method="post" action="xuanze.html">
           <div style="text-align:center;color:#F00">
           <strong>
           <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
           <%
           out.print("正确的题目是:"+zhengque+"<br>"+"错误的题目是:"+error+"<br>"+"点击确定返回主界面"); 
            zhengque="";
        error="";  %>
           <input name="" type="submit" value="确定" />
           </strong>
           </div>
           </form>
           <%
    }
    else
    {
    response.setHeader("refresh","0;url = fenzheng.jsp");
    }
    }
    catch (Exception e) 
    {
        System.out.print("MYSQL ERROR:" + e.getMessage());
    } 
    %>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" import="java.sql.Connection" import="java.sql.DriverManager"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/18.jpg);
    }
    </style>
    </head>
    <body>
    <%!
    int tishu1;
    String error="",zhengque=""; 
    %>
    <%
    try
    {
    Connection con = null; //定义一个MYSQL链接对象
    Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "20153246"); //链接本地MYSQL
    java.sql.Statement stmt; //创建声明
    stmt = con.createStatement();
    String shuju=String.valueOf(session.getAttribute("shuju"));
    String daan=String.valueOf(session.getAttribute("daan"));
    int m=Integer.parseInt(String.valueOf(session.getAttribute("m")));
    tishu1=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
    String daan1=request.getParameter("daan1");
    String sql="INSERT INTO 整数的四则计算 (shizi,result,userresult) VALUES ('"+shuju+" = "+"','"+daan+"','"+daan1+"')";
    stmt.executeUpdate(sql);
    if(daan.equals(daan1))
    {
        zhengque=zhengque+String.valueOf(m+1)+",";
    }
    else
    {
        error=error+String.valueOf(m+1)+",";
    }
    if(m+1==tishu1)
    {
        sql="INSERT INTO Grade (zhengque,cuowu) VALUES ('"+zhengque+"','"+error+"')";
        stmt.executeUpdate(sql);             
        %>
        <form id="form2" name="form2" method="post" action="xuanze.html">
           <div style="text-align:center;color:#F00">
           <strong>
           <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
           <%
           out.print("正确的题目是:"+zhengque+"<br>"+"错误的题目是:"+error+"<br>"+"点击确定返回主界面"); 
            zhengque="";
        error="";  %>
           <input name="" type="submit" value="确定" />
           </strong>
           </div>
           </form>
           <%
    }
    else
    {
    response.setHeader("refresh","0;url = zhengshu.jsp");
    }
    }
    catch (Exception e) 
    {
        System.out.print("MYSQL ERROR:" + e.getMessage());
    } 
    %>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" import="java.util.Random"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/4.jpg);
    }
    </style>
    </head>
    <body>
    <%!
    class Suan1//生成整数计算的类
    {
        public int x,y,c;//定义两个变量,还有一个符号变量
        public Random random=new Random();//定义随机数
        String m;//生成的计算式储存咋m里面
        int fanwei;
        public String shengcheng(int fanwei1)//自动生成数的函数
        {
             fanwei=fanwei1;
             c=random.nextInt(4);//生成符号
             String fuhao;
             x=random.nextInt(fanwei);//生成100以内的自然数
             y=random.nextInt(fanwei);
             if(c==0)//0是加法
             {
                 fuhao="+";
                 m=String.valueOf(x)+fuhao+String.valueOf(y);
                 
             }
             else if(c==1)//1是减法
             {
                 fuhao="-";
                 if(x>=y)
                 {
                     m=String.valueOf(x)+fuhao+String.valueOf(y);
                 }
                 else
                 {
                     m=String.valueOf(y)+fuhao+String.valueOf(x);
                 }
             }
             else if(c==2)
             {
                 fuhao="*";
                 m=String.valueOf(x)+fuhao+String.valueOf(y);
             }
             else
             {
                 fuhao="/";
                 for(int i=0;;i++)
                 {
                     if(y==0)
                     {
                         y=random.nextInt(fanwei);
                     }
                     else
                     {
                         break;
                     }
                 }
                 m=String.valueOf(x)+fuhao+String.valueOf(y);
             }
             return m;
             
        }
        public String shuchu()//定义输出函数
        {
            if(c==0)
            {
                return (String.valueOf(x+y));//并且返回计算的结果
            }
            else if(c==1)
            {
                if(x>=y)//将较大的数放在前面,不能出现负数
                {
                return (String.valueOf(x-y));
                }
                else
                {
                return (String.valueOf(y-x));
                }
            }
            else if(c==2)
            {
                return (String.valueOf(x*y));
            }
            else
            {
                if(x%y==0)
                {
                    return (String.valueOf(x/y));
                }
                else
                {
                    if(x>y)
                    {
                    int shang=x/y;
                    int yushu=x-y*shang;
                    return (String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y));
                    }
                    else
                    {
                    return (String.valueOf(x)+"/"+String.valueOf(y));
                    }
                }
            }
        }
        public int fanhuic()
        {
            return c;
        }
        public String jisuan()
        {
            if(c==0)
            {
                return (String.valueOf(x+y));//并且返回计算的结果
            }
            else if(c==1)
            {
                if(x>=y)//将较大的数放在前面,不能出现负数
                {
                return (String.valueOf(x-y));
                }
                else
                {
                return (String.valueOf(y-x));
                }
            }
            else if(c==2)
            {
                return (String.valueOf(x*y));
            }
            else
            {
                if(x%y==0)
                {
                    return (String.valueOf(x/y));
                }
                else
                {
                return (String.valueOf(x)+"/"+String.valueOf(y));
                }
            }
        }
        public int jianyan(String a[],int s)//检验是否有重复的式子,如果有返回0,没有就返回1
        {
           int flag=1;
           for(int i=0;i<s;i++)
           {
               if(m.equals(a[i]))//数组a里面是生成的式子
               {
                  flag=0;
                  break;
               }
           }
           return flag;
        }
    }
    class Suan4
    {
        public String m;
        public Random random=new Random();
        public Suan1 suan=new Suan1();
        public String a;
        public int b,z;
        public int c;
        public String a1;
        public int panduan;
        public int x,y;
        public String daan;
        public int weizhi;
        public double kuohao()
        {
            panduan=suan.fanhuic();
            if(panduan==3)
            {
                weizhi=a.indexOf("/");
                if(weizhi==-1)
                {
                    z=Integer.parseInt(a);
                    return z;
                }
                else
                {
                x=Integer.parseInt(a.substring(0, weizhi));
                y=Integer.parseInt(a.substring(weizhi+1));    
                return (Double.parseDouble(a.substring(0, weizhi))/Double.parseDouble(a.substring(weizhi+1)));
                }
            }
            else
            {
                z=Integer.parseInt(a);
                return z;
            }
        }
        public String shengcheng(int fanwei)
        {
            a1=suan.shengcheng(fanwei);
            a=suan.jisuan();
            b=random.nextInt(fanwei);
            int c=random.nextInt(4);
            int daan1;
            String fuhao;
            int kuohao=random.nextInt(2);
            if(c==0)//0是加法
             {
                 fuhao="+";
             }
             else if(c==1)//1是减法
             {
                 fuhao="-";
             }
             else
             {
                 fuhao="*";
             }
            double daxiao=kuohao();
            if(kuohao==0)
            {
                if(c==1&&daxiao<b)
                {
                    m=String.valueOf(b)+fuhao+"("+a1+")";
                    if(weizhi!=-1&&panduan==3)
                    {
                        if(c==0)
                        {
                            int x1=b*y;
                            int x2=x+x1;
                            if(x2%y==0)
                            {
                                daan=String.valueOf(x2/y);
                            }
                            else
                            {
                                if(x2>y)
                                {
                                int shang=x2/y;
                                int yushu=x2-y*shang;
                                daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y);
                                }
                                else
                                {
                                daan=String.valueOf(x2)+"/"+String.valueOf(y);
                                }
                            }
                        }
                        else if(c==1)
                        {
                            int x1=b*y;
                            int x2=x1-x;
                            if(x2%y==0)
                            {
                                daan=String.valueOf(x2/y);
                            }
                            else
                            {
                                if(x2>y)
                                {
                                int shang=x2/y;
                                int yushu=x2-y*shang;
                                daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y);
                                }
                                else
                                {
                                daan=String.valueOf(x2)+"/"+String.valueOf(y);
                                }
                            }
                        }
                        else if(c==2)
                        {
                            int x2=x*b;
                            if(x2%y==0)
                            {
                                daan=String.valueOf(x2/y);
                            }
                            else
                            {
                                if(x2>y)
                                {
                                int shang=x2/y;
                                int yushu=x2-y*shang;
                                daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y);
                                }
                                else
                                {
                                daan=String.valueOf(x2)+"/"+String.valueOf(y);
                                }
                            }
                        }
                    }
                    else
                    {
                        if(c==0)
                        {
                            daan=String.valueOf(b+z);
                        }
                        else if(c==1)
                        {
                            daan=String.valueOf(b-z);
                        }
                        else
                        {
                            daan=String.valueOf(b*z);
                        }
                    }
                }
                else
                {
                    m="("+a1+")"+fuhao+String.valueOf(b);
                    if(weizhi!=-1&&panduan==3)
                    {
                        if(c==0)
                        {
                            int x1=b*y;
                            int x2=x+x1;
                            if(x2%y==0)
                            {
                                daan=String.valueOf(x2/y);
                            }
                            else
                            {
                                if(x2>y)
                                {
                                int shang=x2/y;
                                int yushu=x2-y*shang;
                                daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y);
                                }
                                else
                                {
                                daan=String.valueOf(x2)+"/"+String.valueOf(y);
                                }
                            }
                        }
                        else if(c==1)
                        {
                            int x1=b*y;
                            int x2=x-x1;
                            if(x2%y==0)
                            {
                                daan=String.valueOf(x2/y);
                            }
                            else
                            {
                                if(x2>y)
                                {
                                int shang=x2/y;
                                int yushu=x2-y*shang;
                                daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y);
                                }
                                else
                                {
                                daan=String.valueOf(x2)+"/"+String.valueOf(y);
                                }
                            }
                        }
                        else if(c==2)
                        {
                            int x2=x*b;
                            if(x2%y==0)
                            {
                                daan=String.valueOf(x2/y);
                            }
                            else
                            {
                                if(x2>y)
                                {
                                int shang=x2/y;
                                int yushu=x2-y*shang;
                                daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y);
                                }
                                else
                                {
                                daan=String.valueOf(x2)+"/"+String.valueOf(y);
                                }
                            }
                        }
                    }
                    else
                    {
                        if(c==0)
                        {
                            daan=String.valueOf(z+b);
                        }
                        else if(c==1)
                        {
                            daan=String.valueOf(z-b);
                        }
                        else
                        {
                            daan=String.valueOf(z*b);
                        }
                    }
                }
            }
            else
            {
                if(c==1&&daxiao>b)
                {
                    m="("+a1+")"+fuhao+String.valueOf(b);
                    if(weizhi!=-1&&panduan==3)
                    {
                        if(c==0)
                        {
                            int x1=b*y;
                            int x2=x+x1;
                            if(x2%y==0)
                            {
                                daan=String.valueOf(x2/y);
                            }
                            else
                            {
                                if(x2>y)
                                {
                                int shang=x2/y;
                                int yushu=x2-y*shang;
                                daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y);
                                }
                                else
                                {
                                daan=String.valueOf(x2)+"/"+String.valueOf(y);
                                }
                            }
                        }
                        else if(c==1)
                        {
                            int x1=b*y;
                            int x2=x-x1;
                            if(x2%y==0)
                            {
                                daan=String.valueOf(x2/y);
                            }
                            else
                            {
                                if(x2>y)
                                {
                                int shang=x2/y;
                                int yushu=x2-y*shang;
                                daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y);
                                }
                                else
                                {
                                daan=String.valueOf(x2)+"/"+String.valueOf(y);
                                }
                            }
                        }
                        else if(c==2)
                        {
                            int x2=x*b;
                            if(x2%y==0)
                            {
                                daan=String.valueOf(x2/y);
                            }
                            else
                            {
                                if(x2>y)
                                {
                                int shang=x2/y;
                                int yushu=x2-y*shang;
                                daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y);
                                }
                                else
                                {
                                daan=String.valueOf(x2)+"/"+String.valueOf(y);
                                }
                            }
                        }
                    }
                    else
                    {
                        if(c==0)
                        {
                            daan=String.valueOf(z+b);
                        }
                        else if(c==1)
                        {
                            daan=String.valueOf(z-b);
                        }
                        else
                        {
                            daan=String.valueOf(z*b);
                        }
                    }
                }
                else
                {
                    m=String.valueOf(b)+fuhao+"("+a1+")";
                    if(weizhi!=-1&&panduan==3)
                    {
                        if(c==0)
                        {
                            int x1=b*y;
                            int x2=x+x1;
                            if(x2%y==0)
                            {
                                daan=String.valueOf(x2/y);
                            }
                            else
                            {
                                if(x2>y)
                                {
                                int shang=x2/y;
                                int yushu=x2-y*shang;
                                daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y);
                                }
                                else
                                {
                                daan=String.valueOf(x2)+"/"+String.valueOf(y);
                                }
                            }
                        }
                        else if(c==1)
                        {
                            int x1=b*y;
                            int x2=x1-x;
                            if(x2%y==0)
                            {
                                daan=String.valueOf(x2/y);
                            }
                            else
                            {
                                if(x2>y)
                                {
                                int shang=x2/y;
                                int yushu=x2-y*shang;
                                daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y);
                                }
                                else
                                {
                                daan=String.valueOf(x2)+"/"+String.valueOf(y);
                                }
                            }
                        }
                        else if(c==2)
                        {
                            int x2=x*b;
                            if(x2%y==0)
                            {
                                daan=String.valueOf(x2/y);
                            }
                            else
                            {
                                if(x2>y)
                                {
                                int shang=x2/y;
                                int yushu=x2-y*shang;
                                daan=String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y);
                                }
                                else
                                {
                                daan=String.valueOf(x2)+"/"+String.valueOf(y);
                                }
                            }
                        }
                    }
                    else
                    {
                        if(c==0)
                        {
                            daan=String.valueOf(b+z);
                        }
                        else if(c==1)
                        {
                            daan=String.valueOf(b-z);
                        }
                        else
                        {
                            daan=String.valueOf(b*z);
                        }
                    }
                }
            }
            m=m+"=";
            return m;
        }
        public int jianyan(String a[],int l)//检验是否重复的函数
        {
             int flag=1;
               for(int i=0;i<l;i++)
               {
                   if(m.equals(a[i]))
                   {
                      flag=0;
                      break;
                   }
               }
               return flag;
        }
    }
    int tishu;
    int fanwei;
    int m=0;
    String shuju[]=new String[10000]; 
    int flag=0;
    Suan4 a=new Suan4();
    String daan,daan1;
    String zhengque="",cuowu="";
    %>
    <%
    tishu=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
    fanwei=Integer.parseInt((String.valueOf(session.getAttribute("fanwei"))));
    session.setAttribute("tishu", tishu);
    if(m<tishu)//生成30个计算式
    {
        shuju[m]=a.shengcheng(fanwei);//将生成的计算式储存咋数组里面
        flag=a.jianyan(shuju, m);//返回是否有重复
        if(flag==1)//如果没有就是1
        {
        if(m+1==tishu)
        {daan=a.daan;
        session.setAttribute("shuju", shuju[m]);
        session.setAttribute("daan", daan);
        session.setAttribute("m", m);
            %>
        <form id="form2" name="form2" method="post" action="kuohaohuoqu.jsp">
        <div style="text-align:center">
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <%out.print(m+1+"."+shuju[m]+"=");
        m=0;%>
        <br>
        <br>
        <br>
        <br>
        请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
        <input name="" type="submit" value="提交" />
        </div>
        </form>
            <%
        }
        else
        {
            daan=a.daan;
            session.setAttribute("shuju", shuju[m]);
            session.setAttribute("daan", daan);
            session.setAttribute("m", m);
            %>
        <form id="form2" name="form2" method="post" action="kuohaohuoqu.jsp">
        <div style="text-align:center">
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <%out.print(m+1+"."+shuju[m]+"=");%>
        <br>
        <br>
        <br>
        <br>
        请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
        <input name="" type="submit" value="下一个" />
        </div>
        </form>
            <%
            m++;
            flag=0;
        }
        
        }
        else
        {
            response.setHeader("refresh","1;url = kuohao.jsp");
        }
    }
    %>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    try
    {
        int tishu=Integer.parseInt(request.getParameter("geshu"));
        int fanwei=Integer.parseInt(request.getParameter("fanwei"));
        session.setAttribute("tishu", tishu);
        session.setAttribute("fanwei", fanwei);
        response.setHeader("refresh","0;url = kuohao.jsp");
    }
    catch(Exception e)
    {
        %>
        
        <script type="text/javascript">
        alert("输入错误,点击确定返回重新输入!!!")
        </script>
        <%
        response.setHeader("refresh","0;url = kuohaoerror.jsp");
    }
    %>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/7.jpg);
    }
    </style>
    </head>
    <body>
    <form id="form2" name="form2" method="post" action="kuohaochuangdi.jsp">
    <div style="text-align:center;color:#F09">
    <br>
        <br>
        <br>
        <br>
        <br>
        <br>
    请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
    请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
    <input name="" type="submit" value="提交" />
    </div>
    </form>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" import="java.sql.Connection" import="java.sql.DriverManager"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/18.jpg);
    }
    </style>
    </head>
    <body>
    <%!
    int tishu1;
    String error="",zhengque=""; 
    %>
    <%
    try
    {
    Connection con = null; //定义一个MYSQL链接对象
    Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "20153246"); //链接本地MYSQL
    java.sql.Statement stmt; //创建声明
    stmt = con.createStatement();
    String shuju=String.valueOf(session.getAttribute("shuju"));
    String daan=String.valueOf(session.getAttribute("daan"));
    int m=Integer.parseInt(String.valueOf(session.getAttribute("m")));
    tishu1=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
    String daan1=request.getParameter("daan1");
    String sql="INSERT INTO 有括号的四则运算 (shizi,result,userresult) VALUES ('"+shuju+" = "+"','"+daan+"','"+daan1+"')";
    stmt.executeUpdate(sql);
    if(daan.equals(daan1))
    {
        zhengque=zhengque+String.valueOf(m+1)+",";
    }
    else
    {
        error=error+String.valueOf(m+1)+",";
    }
    if(m+1==tishu1)
    {
        sql="INSERT INTO Grade (zhengque,cuowu) VALUES ('"+zhengque+"','"+error+"')";
        stmt.executeUpdate(sql);             
        
        %>
       <form id="form2" name="form2" method="post" action="xuanze.html">
           <div style="text-align:center;color:#F00">
           <strong>
           <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
           <%
           out.print("正确的题目是:"+zhengque+"<br>"+"错误的题目是:"+error+"<br>"+"点击确定返回主界面"); 
            zhengque="";
        error="";  %>
           <input name="" type="submit" value="确定" />
           </strong>
           </div>
           </form>
           <%
    }
    else
    {
    response.setHeader("refresh","0;url = kuohao.jsp");
    }
    }
    catch (Exception e) 
    {
        System.out.print("MYSQL ERROR:" + e.getMessage());
    } 
    %>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/7.jpg);
    }
    </style>
    </head>
    <body>
    <%
     String panduan=request.getParameter("xuanze");
    if(panduan.equals("A"))
    {
        %>
        <form id="form2" name="form2" method="post" action="chaundi.jsp">
        <div style="text-align:center;color:#F09">
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
        请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
        <input name="" type="submit" value="提交" />
        </div>
        </form>
        <%
    }
    else if(panduan.equals("B"))
    {
        %>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <form id="form3" name="form4" method="post" action="fenchuandi.jsp">
        <div style="text-align:center;color:#F09">
        请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
        请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
        <input name="" type="submit" value="提交" />
        </div>
        </form>
        <%
    }
    else if(panduan.equals("C"))
    {
        %>
        <form id="form2" name="form2" method="post" action="fenzhengchuangdi.jsp">
        <div style="text-align:center;color:#F09">
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
        请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
        <input name="" type="submit" value="提交" />
        </div>
        </form>
        <%
    }
    else if(panduan.equals("D"))
    {
         %>
         <form id="form2" name="form2" method="post" action="yushuchuangdi.jsp">
        <div style="text-align:center;color:#F09">
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
        请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
        <input name="" type="submit" value="提交" />
        </div>
        </form>
        <%
    }
    else if(panduan.equals("E"))
    {
        %>
        <form id="form2" name="form2" method="post" action="kuohaochuangdi.jsp">
        <div style="text-align:center;color:#F09">
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
        请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
        <input name="" type="submit" value="提交" />
        </div>
        </form>
        <% 
    }
    else
    {
        %>
        <script type="text/javascript">
        alert("输入错误,请点击确定重新输入!!!");
        </script>
        <% 
        response.setHeader("refresh","0;url = xuanze.html");
    }
        %>
    </body>
    </html>
    View Code
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>主界面</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/17.jpg);
    }
    </style>
    </head>
    <body>
    <div style="text-align: center; font-family: 微软雅黑; font-size: 50px; color: #C03; "><strong><em>四则运算</em></strong></div>
    <div style="text-align: center; font-family: 微软雅黑; font-size: 15px; color: #C03; "><strong><em>Welcome To User The System</em></strong></div>
    <br/>
    <div style="text-align: center; font-family: 微软雅黑; font-size: 20px;color: #C03;"><strong><em>请选择出题的范围</em></strong></div><br />
    <form  name="form1" method="post" action="panduan.jsp">
    <blockquote>
      <blockquote>
        <blockquote>
          <blockquote>
            <blockquote>
              <blockquote>
                <blockquote>
                 <blockquote>
                  <blockquote>
                   <blockquote>
                   <div style="color: #C03">
                  <p> <strong>A:整数的四则计算<br />
                    B:真分数的四则计算<br />
                    C:整数与真分数的混合四则运算<br />
                    D:有余数的除法<br />
                    E:有括号的四则运算<br />
                    </strong>
                  </p>
                  </div>
                  </blockquote>
                  </blockquote>
                  </blockquote>
                </blockquote>
              </blockquote>
            </blockquote>
          </blockquote>
        </blockquote>
      </blockquote>
    </blockquote>
    <div style="text-align: center;color: #C03 ">
    <strong>请选择:</strong><input name="xuanze" type="text"/>
    <input name="" type="submit" value="提交"  />
    <input name="" type="reset" value="重置" />
    </div>
    </form>
    </body>
    </html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" import="java.util.Random"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/4.jpg);
    }
    </style>
    </head>
    <body>
    <%!
    class Suan3//有余数的类
    {
        public int x,y;//定义两个变量
        public String m;
        public Random random=new Random();
        int fanwei;
        public String shengcheng(int fanwei1)//定义生成函数
        {
            fanwei=fanwei1;
            x=random.nextInt(fanwei);
            y=random.nextInt(fanwei);
            for(int i=0;;i++)
            {
                if(y==0)
                {
                    y=random.nextInt(fanwei);
                }
                else
                {
                    break;
                }
            }
            m=String.valueOf(x)+"/"+String.valueOf(y);//返回计算式
            return m;
        }
        public String shuchu()//生成输出函数
        {
            String daan;
            int shang,yushu;
            shang=x/y;
            yushu=x-shang*y;
            daan=String.valueOf(shang)+"/"+String.valueOf(yushu);//返回计算结果
            return daan;
        }
        public int jianyan(String a[],int l)//检验是否重复的函数
        {
             int flag=1;
               for(int i=0;i<l;i++)
               {
                   if(m.equals(a[i]))
                   {
                      flag=0;
                      break;
                   }
               }
               return flag;
        }
    }
    int tishu;
    int fanwei;
    int m=0;
    String shuju[]=new String[10000]; 
    int flag=0;
    Suan3 a=new Suan3();
    String daan,daan1;
    %>
    <%
    
    tishu=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
    fanwei=Integer.parseInt((String.valueOf(session.getAttribute("fanwei"))));
    session.setAttribute("tishu", tishu);
    if(m<tishu)
    {
        shuju[m]=a.shengcheng(fanwei);
        flag=a.jianyan(shuju, m);//返回是否有重复
        if(flag==1)//如果没有就是1
        {
        if(m+1==tishu)
        {daan=a.shuchu();
        session.setAttribute("shuju", shuju[m]);
        session.setAttribute("daan", daan);
        session.setAttribute("m", m);
            %>
        <form id="form2" name="form2" method="post" action="yushuhuoqu.jsp">
        <div style="text-align:center">
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <%out.print(m+1+"."+shuju[m]+"=");
        m=0;%>
        <br>
        <br>
        <br>
        <br>
        请输入商:<input name="daan1" type="text" value=""/><br /><br/>
        请输入余数:<input name="daan2" type="text" value=""/><br>
        <br>
        <input name="" type="submit" value="提交" />
        </div>
        </form>
            <%
        }
        else
        {
            daan=a.shuchu();
            session.setAttribute("shuju", shuju[m]);
            session.setAttribute("daan", daan);
            session.setAttribute("m", m);
            %>
        <form id="form2" name="form2" method="post" action="yushuhuoqu.jsp">
        <div style="text-align:center">
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <%out.print(m+1+"."+shuju[m]+"=");%>
        <br>
        <br>
        <br>
        <br>
        请输入商:<input name="daan1" type="text" value=""/><br /><br/>
        请输入余数:<input name="daan2" type="text" value=""/><br>
        <br>
        <input name="" type="submit" value="下一个" />
        </div>
        </form>
            <%
            m++;
            flag=0;
        }
        
        }
        else
        {
            response.setHeader("refresh","0;url = yushu.jsp");
        }
    }
    %>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    try
    {
        int tishu=Integer.parseInt(request.getParameter("geshu"));
        int fanwei=Integer.parseInt(request.getParameter("fanwei"));
        session.setAttribute("tishu", tishu);
        session.setAttribute("fanwei", fanwei);
        response.setHeader("refresh","0;url = yushu.jsp");
    }
    catch(Exception e)
    {
        %>
        <script type="text/javascript">
        alert("输入错误,点击确定返回重新输入!!!")
        </script>
        <%
        response.setHeader("refresh","0;url = yushuerror.jsp");
    }
    %>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/7.jpg);
    }
    </style>
    </head>
    <body>
    <form id="form2" name="form2" method="post" action="yushuchuangdi.jsp">
    <div style="text-align:center;color:#F09">
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    请输入出题的个数:<input name="geshu" type="text" value=""/><br /><br/>
    请选择出题的范围:<input name="fanwei" type="text" value=""/><br/><br/>
    <input name="" type="submit" value="提交" />
    </div>
    </form>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" import="java.sql.Connection" import="java.sql.DriverManager"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/18.jpg);
    }
    </style>
    </head>
    <body>
    <%!
    int tishu1;
    String error="",zhengque=""; 
    %>
    <%
    try
    {
    Connection con = null; //定义一个MYSQL链接对象
    Class.forName("com.mysql.jdbc.Driver").newInstance(); //MYSQL驱动
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "20153246"); //链接本地MYSQL
    java.sql.Statement stmt; //创建声明
    stmt = con.createStatement();
    String shuju=String.valueOf(session.getAttribute("shuju"));
    String daan=String.valueOf(session.getAttribute("daan"));
    int weizhi=daan.indexOf('/');
    String shang1=daan.substring(0, weizhi);
    String yushu1=daan.substring(weizhi+1);
    int m=Integer.parseInt(String.valueOf(session.getAttribute("m")));
    tishu1=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
    String shang =request.getParameter("daan1");
    String yushu =request.getParameter("daan2");
    String sql="INSERT INTO 有余数的除法 (shizi,shang,yushu,usershang,useryushu) VALUES ('"+shuju+" = "+"','"+shang1+"','"+yushu1+"','"+shang+"','"+yushu+"')";
    stmt.executeUpdate(sql);
    if(daan.equals(shang+"/"+yushu))
    {
        zhengque=zhengque+String.valueOf(m+1)+",";
    }
    else
    {
        error=error+String.valueOf(m+1)+",";
    }
    if(m+1==tishu1)
    {
        sql="INSERT INTO Grade (zhengque,cuowu) VALUES ('"+zhengque+"','"+error+"')";
        stmt.executeUpdate(sql);             
        
        %>
        <form id="form2" name="form2" method="post" action="xuanze.html">
           <div style="text-align:center;color:#F00">
           <strong>
           <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
           <%
           out.print("正确的题目是:"+zhengque+"<br>"+"错误的题目是:"+error+"<br>"+"点击确定返回主界面"); 
            zhengque="";
        error="";  %>
           <input name="" type="submit" value="确定" />
           </strong>
           </div>
           </form>
           <%
    }
    else
    {
    response.setHeader("refresh","0;url = yushu.jsp");
    }
    }
    catch (Exception e) 
    {
        System.out.print("MYSQL ERROR:" + e.getMessage());
    } 
    %>
    </body>
    </html>
    View Code
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8" import="java.util.Random" import="java.sql.Connection" import="java.sql.DriverManager"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    body 
    {
        background-image: url(image/4.jpg);
    }
    </style>
    </head>
    <body>
    <%!
    class Suan1//生成整数计算的类
    {
        public int x,y,c;//定义两个变量,还有一个符号变量
        public Random random=new Random();//定义随机数
        String m;//生成的计算式储存咋m里面
        int fanwei;
        public String shengcheng(int fanwei1)//自动生成数的函数
        {
             fanwei=fanwei1;
             c=random.nextInt(4);//生成符号
             String fuhao;
             x=random.nextInt(fanwei);//生成100以内的自然数
             y=random.nextInt(fanwei);
             if(c==0)//0是加法
             {
                 fuhao="+";
                 m=String.valueOf(x)+fuhao+String.valueOf(y);
                 
             }
             else if(c==1)//1是减法
             {
                 fuhao="-";
                 if(x>=y)
                 {
                     m=String.valueOf(x)+fuhao+String.valueOf(y);
                 }
                 else
                 {
                     m=String.valueOf(y)+fuhao+String.valueOf(x);
                 }
             }
             else if(c==2)
             {
                 fuhao="*";
                 m=String.valueOf(x)+fuhao+String.valueOf(y);
             }
             else
             {
                 fuhao="/";
                 for(int i=0;;i++)
                 {
                     if(y==0)
                     {
                         y=random.nextInt(fanwei);
                     }
                     else
                     {
                         break;
                     }
                 }
                 m=String.valueOf(x)+fuhao+String.valueOf(y);
             }
             return m;
             
        }
        public String shuchu()//定义输出函数
        {
            if(c==0)
            {
                return (String.valueOf(x+y));//并且返回计算的结果
            }
            else if(c==1)
            {
                if(x>=y)//将较大的数放在前面,不能出现负数
                {
                return (String.valueOf(x-y));
                }
                else
                {
                return (String.valueOf(y-x));
                }
            }
            else if(c==2)
            {
                return (String.valueOf(x*y));
            }
            else
            {
                if(x%y==0)
                {
                    return (String.valueOf(x/y));
                }
                else
                {
                    if(x>y)
                    {
                    int shang=x/y;
                    int yushu=x-y*shang;
                    return (String.valueOf(shang)+"‘"+String.valueOf(yushu)+"/"+String.valueOf(y));
                    }
                    else
                    {
                    return (String.valueOf(x)+"/"+String.valueOf(y));
                    }
                }
            }
        }
        public int fanhuic()
        {
            return c;
        }
        public int jianyan(String a[],int s)//检验是否有重复的式子,如果有返回0,没有就返回1
        {
           int flag=1;
           for(int i=0;i<s;i++)
           {
               if(m.equals(a[i]))//数组a里面是生成的式子
               {
                  flag=0;
                  break;
               }
           }
           return flag;
        }
    }
    int tishu;
    int fanwei;
    int m=0;
    String shuju[]=new String[10000]; 
    int flag=0;
    Suan1 a=new Suan1();
    String daan,daan1;
    String zhengque="",cuowu="";
    %>
    <%
    tishu=Integer.parseInt((String.valueOf(session.getAttribute("tishu"))));
    fanwei=Integer.parseInt((String.valueOf(session.getAttribute("fanwei"))));
    session.setAttribute("tishu", tishu);
    if(m<tishu)//生成30个计算式
    {
        shuju[m]=a.shengcheng(fanwei);//将生成的计算式储存咋数组里面
        flag=a.jianyan(shuju, m);//返回是否有重复
        if(flag==1)//如果没有就是1
        {
        if(m+1==tishu)
        {daan=a.shuchu();
        session.setAttribute("shuju", shuju[m]);
        session.setAttribute("daan", daan);
        session.setAttribute("m", m);
            %>
        <form id="form2" name="form2" method="post" action="huoqu.jsp">
        <div style="text-align:center">
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <%out.print(m+1+"."+shuju[m]+"=");
        m=0;%>
        <br>
        <br>
        <br>
        <br>
        请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
        <input name="" type="submit" value="提交" />
        </div>
        </form>
            <%
        }
        else
        {
            daan=a.shuchu();
            session.setAttribute("shuju", shuju[m]);
            session.setAttribute("daan", daan);
            session.setAttribute("m", m);
            %>
        <form id="form2" name="form2" method="post" action="huoqu.jsp">
        <div style="text-align:center">
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <br>
        <%out.print(m+1+"."+shuju[m]+"=");%>
        <br>
        <br>
        <br>
        <br>
        请输入答案:<input name="daan1" type="text" value=""/><br /><br/>
        <input name="" type="submit" value="下一个" />
        </div>
        </form>
            <%
            m++;
            flag=0;
        }
        
        }
        else
        {
            response.setHeader("refresh","1;url = zhengshu.jsp");
        }
    }
    %>
    
    
    </body>
    </html>
    View Code

    小组成员:解昊兴  谢梦雨

       

  • 相关阅读:
    oracle中Blob和Clob类型的区别
    为什么要分库分表
    Enable file editing in Visual Studio's debug mode
    SQL Server Dead Lock Log
    Debug .NET Framework Source
    SQL Server text field里面有换行符的时候copy到excel数据会散乱
    诊断和修复Web测试记录器(Web Test Recorder)问题
    Can't load Microsoft.ReportViewer.ProcessingObjectModel.dll
    'telnet' is not recognized as an internal or external command
    Linq to XML
  • 原文地址:https://www.cnblogs.com/xhxdeblog/p/6679629.html
Copyright © 2020-2023  润新知