四则运算网页版

一.设计思想:

  1)写出一个菜单界面,有两个选项一个是分数,一个是整数。

     2)而这两个标签后面则是转向其更详细的菜单,题目数量,有无括号,运算的项数等等详细功能,再点击这两个按钮之后,就会跳转过去。 

     3)当选择整数运算时,显示出需要的菜单,输入完要求之后,跳转到生成算式的JSP文件,在此文件中首先是用request方法来获取上个页

面中你所需要的功能,然后再强制类型转化来为下面使用,通过随机数生成,分别生成参与运算的数和符号,0代表加法1代表减法3代表乘法4代

表除法。选择有负数和有余数式子生成,选择没有负数或者没有余数的情况下,就需要将随机的数进行运算,符合条件flag=1,不符合条件的flag

=0。定义一个数来表示他的结果,在每个运算符号的if语句中,将结果运算出来,在整个式子都通过前面的用户需求时,将运算数和符号连成一个

字符串,然后再进行查重,如果没有重复则flag1=1,如果有重复flag1=0。当全部满足条件时,在页面中显示出来,并且在式子右侧写一个文本

框用来填写结果。然后设置一个统计按钮,填完结果之后,统计的答题情况,我们是用session方法来保存式子数组和答案数组的。然后跳转到核对界

面进行核对,如果对了提示回答正确,count++,如果错误提示错误。上面是两个数的运算,多个数的运算则是用的先生成两个数的运算,然后在随

机是否生成括号,如果生成然后在随机括号的位置是在这一组上的前面加括号,还是后面加括号。上面就是整数部分的运算。

    4)分数部分的运算和整数部分差不多,首先随机生成四个数两个构成一个分数,然后再定义个随机数来表示运算符。然后,分子分母进行比较

,是否是真分数。如果不是此次循环结束,i--重新开始。需要满足的条件基本上和整数差不多,不过需要在jsp中写一个求最大公约数的方法,来进行

化简,在运算的时候先运算然后进行化简。最后数字和符号组成字符串,结果字符串。通过session方法进行保存。跳到核对界面进行核对。多个分数

运算有无括号和整数的原理也一致。最后来说说数据库,在jsp中连接数据库的话和在.java文件中连接有所不同,在加载驱动时,加载驱动语句右面要

加.Instance();才能加载成功。然后在情况下,所满足条件的生成式子。通过SQL增加语句进行写入数据库。

二.程序源代码:

  开始界面

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>菜单页面</title></head>
<body ><div align="center"><br/><br/><br/><br/><br/><br/><a href="zs.jsp"  >●整数运算</a><br/><br/><a href="fens.jsp">⊙分数运算</a></div>
</body>
</html>

整数菜单

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>整数二级菜单页面</title>
 8 </head>
 9 <body>
10     <form name="form1" method=post action="index.jsp">
11     <center> 整数四则运算</center>
12     <table align="center">
13     <tr>
14     <td>请输入需要生成的题目数量</td>
15     <td><input name="shuliang" id="shuliang" type="text" > </td>
16     </tr>
17     <tr>
18     <td>
19          请输入最小值
20     </td>
21         <td>
22         <input name="zuixiao" id="zuixiao" type="text">
23         </td>
24     </tr>
25      <tr>
26      <td>请输入最大值</td>
27      <td> <input name="zuida" id="zuida" type="text"> </td>
28      </tr>
29      <tr>
30      <td> 请选择是否需要括号1有2没有</td>
31      <td> <input name="kuohao" id="kuohao" type="text"> </td>
32      </tr>
33      <tr>
34       <td>请选择生成算式的位数1两位数2多位数</td>
35       <td><input name="weishu" id="weishu" type="text"> </td>
36      </tr>
37      <tr>
38       <td>加减有无负数</td>
39       <td><input name="fs" id="fs" type="text"> </td>
40       </tr>
41       <tr>
42       <td> 除法有无余数</td>
43       <td><input name="ys" id="ys"type="text"></td>
44       </tr>
45     </table>
46         <center><input type="submit" value="开始出题"> </center>
47     </form>
48 </body>
49 </html>

整数试题和填写

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="java.sql.Connection,java.sql.DriverManager,java.sql.ResultSet"%>
<!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>整数页面</title>
</head>
<body>
<%String driverStr = "com.microsoft.sqlserver.jdbc.SQLServerDriver";Class.forName(driverStr).newInstance();String connStr = "jdbc:sqlserver://localhost:1433; DatabaseName=Webys";String dbusername = "sa";String dbpassword = "123456";Connection conn=null;java.sql.Statement stmt=null;conn=DriverManager.getConnection(connStr, dbusername, dbpassword);stmt=conn.createStatement();String weishu=request.getParameter("weishu");String kuohao=request.getParameter("kuohao");String zuix=request.getParameter("zuixiao");String zuid=request.getParameter("zuida");String fss=request.getParameter("fs");String yss=request.getParameter("ys");if(Integer.parseInt(weishu)==1){int ans=0;String j=request.getParameter("shuliang");int sl=Integer.valueOf(j);int litt=Integer.valueOf(zuix);int bi=Integer.valueOf(zuid);String []ss=new String[sl];String s="";String daan[] =new String [sl];String ans2[]=new String[sl];int a[]=new int [sl];int b[]=new int [sl];int flag=0;int flag1=0;   int c[]=new int [sl];int d[]=new int[sl];int e[]=new int[sl];int fs=Integer.valueOf(fss);int ys=Integer.valueOf(yss);for(int i=0;i<sl;i++){daan[i]="name"+i;flag1=0;a[i]=(int)(Math.random()*(bi-litt)+1+litt);b[i]=(int)(Math.random()*(bi-litt)+1+litt);c[i]=(int)(Math.floor((Math.random()*4)));if(fs==1){flag=0;}if(fs==2){if(c[i]==1){if((a[i]-b[i])>=0){flag=0;}else{flag=1;}}}if(c[i]==0){s=" + ";ans=a[i]+b[i];}if(c[i]==1){s=" - ";ans=a[i]-b[i];}if(c[i]==2){s=" * ";ans=a[i]*b[i];}if(c[i]==3){if(b[i]!=0){if(ys==1){s=" ÷ ";ans=a[i]/b[i];}if(ys==2){if((a[i]%b[i])==0){s=" ÷ ";ans=a[i]/b[i];}else{flag=1;}}}elseflag=1;}ss[i]=a[i]+s+b[i];for(int i1=0;i1<i;i1++)   //查重{if((a[i1]==a[i])&&(b[i1]==b[i])&&(c[i1]==c[i]))flag1=1;           if((a[i1]==b[i])&&(b[i1]==a[i])&&(c[i1]==0)&&(c[i]==0))flag1=1;if((a[i1]==b[i])&&(b[i1]==a[i])&&(c[i1]==2)&&(c[i]==2))flag1=1;}if((flag==0)&&(flag1==0))  //输出{String sql="INSERT INTO size VALUES ('"+ss[i]+"','"+ans+"')";stmt.executeUpdate(sql);ans2[i]=""+ans;out.print(ss[i]);%><br><form name="form2" method="post" action="zscheck2.jsp">请输入答案<input name=<%=daan[i] %> type="text" id="daan"><br/>                <%  }else{i--;}}session.setAttribute("v1", ss);session.setAttribute("v2", ans2);%><input type="submit" value="统计结果"> </form><%}if(Integer.parseInt(weishu)==2){String j=request.getParameter("shuliang");int sl=Integer.valueOf(j);int litt=Integer.valueOf(zuix);int bi=Integer.valueOf(zuid);String []ss=new String[sl];String s="";String daan[] =new String [sl];int a[]=new int [sl];int b[]=new int [sl];int flag=0;int flag1=0;String [] ans2=new String[sl];int ans=0;int c[]=new int [sl];int d[]=new int[sl];int e[]=new int[sl];int fs=Integer.valueOf(fss);int ys=Integer.valueOf(yss);int y=0;int y1=0;int y2=0;String j1=request.getParameter("kuohao");int y3=Integer.valueOf(j1);for(int i=0;i<sl;i++){daan[i]="name"+i;int c1 []=new int [20000];flag1=0;y=(int )(Math.random()*4+3);//生成数的个数y1=(int )(Math.random()*2);//有无括号y2=(int )(Math.random()*2);//前后a[i]=(int)(Math.random()*(bi-litt)+1+litt);b[i]=(int)(Math.random()*(bi-litt)+1+litt);c[i]=(int)(Math.floor((Math.random()*4)));if(fs==1){flag=0;}if(fs==2)// 没有负数{if(c[i]==1){if((a[i]-b[i])>=0){flag=0;}else{flag=1;}}}if(c[i]==0){s=" + ";ans=a[i]+b[i];}if(c[i]==1){s=" - ";ans=a[i]-b[i];}if(c[i]==2){s=" * ";ans=a[i]*b[i];}if(c[i]==3){if(b[i]!=0){if(ys==1){s=" ÷ ";ans=a[i]/b[i];}if(ys==2){if((a[i]%b[i])==0){s=" ÷ ";ans=a[i]/b[i];}elseflag=1;}}elseflag=1;}ss[i]=a[i]+s+b[i];if(y3==1)//有括号生成{for(int  r=0;r<(y-2);r++){y1=(int )(Math.random()*2);//有无括号y2=(int )(Math.random()*2);//前后d[r]=(int)(Math.random()*(bi-litt)+1+litt);c1[i]=(int )(Math.random()*4);if(c1[i]==0){s=" + ";ans=ans+d[r];}if(c1[i]==1){s=" - ";ans=ans-d[r];}if(c1[i]==2){s=" * ";ans=ans*d[r];}if(c1[i]==3){if(b[i]!=0){if(ys==1){s=" ÷ ";ans=ans/d[r];}if(ys==2){if((a[i]%b[i])==0){s=" ÷ ";ans=ans/d[r];}elseflag=1;}}elseflag=1;}if(y1==1) //随机数生成没有括号情况{if(y2==0) //加在后面{ss[i]=ss[i]+s+d[r];}if(y2==1)  //加在前面{ss[i]=d[r]+s+ss[i];}}if(y1==0) //随机数生成了括号{if(y2==0)  //加在后面{ss[i]="("+ss[i]+")"+s+d[r];}if(y2==1)  //括号加在前边{ss[i]=d[r]+s+"("+ss[i]+")";}}for(int i2=0;i2<i;i2++){if(ss[i2]==ss[i])flag1=1;elseflag1=0;}}}if(y3==2){for(int  r=0;r<(y-2);r++){y1=(int)(Math.random()*2);//有无括号y2=(int)(Math.random()*2);//前后d[r]=(int)(Math.random()*(bi-litt)+1+litt);c1[i]=(int)(Math.random()*4);if(c1[i]==0){s=" + ";ans=ans+d[r];}if(c1[i]==1){s=" - ";ans=ans-d[r];}if(c1[i]==2){s=" * ";ans=ans*d[r];}if(c1[i]==3){if(b[i]!=0){if(ys==1){s=" ÷ ";ans=ans/d[r];}if(ys==2){if((a[i]%b[i])==0){s=" ÷ ";ans=ans/d[r];}elseflag=1;}}elseflag=1;}if(y1==1) //没有括号{if(y2==0) //加在后面{ss[i]=ss[i]+s+d[r];}if(y2==1)  {ss[i]=d[r]+s+ss[i];}}for(int i2=0;i2<i;i2++){if(ss[i2]==ss[i])flag1=1;elseflag1=0;}} //小for 循环}if((flag==0)&&(flag1==0)){String sql="INSERT INTO size VALUES ('"+ss[i]+"','"+ans+"')";stmt.executeUpdate(sql);ans2[i]=""+ans;out.print(ss[i]+" "); %><br><form name="form2" method="post" action="zscheck2.jsp">请输入答案<input name=<%=daan[i] %> type="text" id="daan"><br/>             <%}elsei--;}session.setAttribute("v1", ss);session.setAttribute("v2", ans2);%><input type="submit" value="统计结果"> </form><%}%></body>
</html>

结果核查

<%@ 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><%String[] s1= (String[])session.getAttribute("v1");String[] answer= (String[])session.getAttribute("v2");String[] daan=new String[s1.length];int count=0;//正确答案的个数for(int i=0;i<s1.length;i++){out.print("运算式为:");out.print(s1[i]+"  ");out.print("您的输入结果为:");daan[i]=request.getParameter("name"+i);out.print(daan[i]+"   ");out.print("正确结果为:");out.print(answer[i]);if(Integer.parseInt(daan[i])==Integer.parseInt(answer[i])){out.print("恭喜你答对了!");count++;}else{out.print("很遗憾,你答错了!");}out.print("<br>");}out.print("你一共答对的题目数:");out.print(count);%>
</body>
</html>

<%@ 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>分数二级菜单</title></head>
<body ><form name="form3" method=post action="fes.jsp"><center> 整数四则运算</center><table align="center"><tr><td>请输入需要生成的题目数量</td><td><input name="shuliang" id="shuliang" type="text" > </td></tr><tr><td>请输入分数的最大值</td><td> <input name="zuida" id="zuida" type="text"> </td></tr><tr><td> 请选择是否需要括号1有2没有</td><td> <input name="kuohao" id="kuohao" type="text"> </td></tr><tr><td>请选择生成算式的位数1两位数2多位数</td><td><input name="weishu" id="weishu" type="text"> </td></tr><tr><td>加减有无负数</td><td><input name="fs" id="fs" type="text"> </td></tr><tr><td> 除法有无余数</td><td><input name="ys" id="ys"type="text"></td></tr></table><center><input type="submit" value="开始出题"> </center></form>
</body>
</html>

分数出题:

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" import="java.sql.Connection,java.sql.DriverManager,java.sql.ResultSet"%>
<!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>
<%!class gg{int gongbei(int x,int y){int z;for(z=x;;z++){if(z%x==0&&z%y==0)break;}return z;}int gongyue(int x,int y){int z;for(z=x;z>0;z--){if(x%z==0&&y%z==0)break;}return z;}}
%>
<%String driverStr = "com.microsoft.sqlserver.jdbc.SQLServerDriver";Class.forName(driverStr).newInstance();String connStr = "jdbc:sqlserver://localhost:1433; DatabaseName=Webys";String dbusername = "sa";String dbpassword = "123456";Connection conn=null;java.sql.Statement stmt=null;conn=DriverManager.getConnection(connStr, dbusername, dbpassword);stmt=conn.createStatement();String weishu=request.getParameter("weishu");String kuohao=request.getParameter("kuohao");String zuid=request.getParameter("zuida");String fss=request.getParameter("fs");String yss=request.getParameter("ys");gg g=new gg();if(Integer.parseInt(weishu)==1){int fenzi=0;int fenmu=0;int huajian=0;String j=request.getParameter("shuliang");int sl=Integer.valueOf(j);int bi=Integer.valueOf(zuid);String []ss=new String[sl];String daan[] =new String [sl];String jj[]=new String[sl];String s="";int ans=0;String ans1[]=new String[sl];int a[]=new int [sl];int a1[]=new int[sl];int b[]=new int [sl];int b1[]=new int[sl];int flag=0;int flag1=0;int flag2=0;int flag3=0;int c[]=new int [sl];int d[]=new int[sl];int d1[]=new int[sl];int e[]=new int[sl];int fs=Integer.valueOf(fss);int ys=Integer.valueOf(yss);for(int i=0;i<sl;i++){daan[i]="name"+i;flag1=0;flag2=0;a[i]=(int)(Math.random()*(bi-1-1)+1);a1[i]=(int)(Math.random()*(bi-1)+1);b[i]=(int)(Math.random()*(bi-1-1)+1);b1[i]=(int)(Math.random()*(bi-1)+1);c[i]=(int)(Math.random()*4);if((a[i]>=a1[i])||(b[i]>=b1[i])) //判断是否为真分数{flag2=1;}else   //是真分数继续进行{flag2=0;}if(fs==1)  //有负数{flag=0;}if(fs==2)  //没有负数{if(c[i]==1){if((a[i]*b1[i]-a1[i]*b[i])>=0){flag=0;}else{flag=1;}}}if(c[i]==0){s=" + ";fenzi=(a[i]*b1[i])+(a1[i]*b[i]);fenmu=a1[i]*b1[i];huajian=g.gongyue(fenzi, fenmu);int o=fenzi/huajian;int p=fenmu/huajian;if(o<p){jj[i]=o+"/"+p;}if((o>p)&&(o%p!=0)){int you=o/p;o=o-p*you;jj[i]=you+"|"+o+"/"+p;}if((o>p)&&(o%p==0)){int you=o/p;jj[i]=""+you;}}if(c[i]==1){s=" - ";fenzi=(a[i]*b1[i])-(a1[i]*b[i]);fenmu=a1[i]*b1[i];if(fenzi>0){huajian=g.gongyue(fenzi, fenmu);int o=fenzi/huajian;int p=fenmu/huajian;if(o<p){jj[i]=o+"/"+p;}if((o>p)&&(o%p!=0)){int you=o%p;o=o-p*you;jj[i]=you+"|"+o+"/"+p;}if((o>p)&&(o%p==0)){int you=o%p;jj[i]=""+you;}}if(fenzi<0){int t=0-fenzi;huajian=g.gongyue(t, fenmu);int o=fenzi/huajian;int p=fenmu/huajian;if(o<p){jj[i]=o+"/"+p;}if((o>p)&&(o%p!=0)){int you=o/p;o=o-p*you;jj[i]=you+"|"+o+"/"+p;}if((o>p)&&(o%p==0)){int you=o/p;jj[i]=""+you;}}if(fenzi==0){jj[i]=""+0;}}if(c[i]==2){s=" * ";fenzi=a[i]*b[i];fenmu=a1[i]*b1[i];huajian=g.gongyue(fenzi, fenmu);int o=fenzi/huajian;int p=fenmu/huajian;if(o<p){jj[i]=o+"/"+p;}if((o>p)&&(o%p!=0)){int you=o/p;o=o-p*you;jj[i]=you+"|"+o+"/"+p;}if((o>p)&&(o%p==0)){int you=o/p;jj[i]=""+you;}}if(c[i]==3){if(ys==1){s=" ÷ ";fenzi=a[i]*b1[i];fenmu=a1[i]*b[i];huajian=g.gongyue(fenzi,fenmu);int o=fenzi/huajian;int p=fenmu/huajian;if(o<p){jj[i]=o+"/"+p;}if((o>p)&&(o%p!=0)){int you=o/p;o=o-p*you;jj[i]=you+"|"+o+"/"+p;}if((o>p)&&(o%p==0)){int you=o/p;jj[i]=""+you;}}if(ys==2){if(((a[i]*b1[i])%(a1[i]*b[i]))==0){s=" ÷ ";fenzi=a[i]*b1[i];fenmu=a1[i]*b[i];huajian=g.gongyue(fenzi,fenmu);int o=fenzi/huajian;int p=fenmu/huajian;if(o<p){jj[i]=o+"/"+p;}if((o>p)&&(o%p!=0)){int you=o%p;o=o-p*you;jj[i]=you+"|"+o+"/"+p;}if((o>p)&&(o%p==0)){int you=o%p;jj[i]=you+"";}}else{flag=1;}}}int y=g.gongyue(a[i],a1[i]);int y1=g.gongyue(b[i],b1[i]);a[i]=a[i]/y;a1[i]=a1[i]/y;b[i]=b[i]/y1;b1[i]=b1[i]/y1;ss[i]=a[i]+"/"+a1[i]+s+b[i]+"/"+b1[i];for(int i1=0;i1<i;i1++)   //查重{if((a[i1]==a[i])&&(a1[i1]==a1[i])&&(b[i1]==b[i])&&(b1[i]==b1[i1])&&(c[i1]==c[i]))flag1=1;           if((a[i1]==b[i])&&(b[i1]==a[i])&&(c[i1]==0)&&(c[i]==0)&&(a1[i1]==b1[i])&&(b1[i1]==a1[i]))flag1=1;if((a[i1]==b[i])&&(b[i1]==a[i])&&(c[i1]==2)&&(c[i]==2)&&(a1[i1]==b1[i])&&(b1[i1]==a1[i]))flag1=1;}if((flag==0)&&(flag1==0)&&(flag2==0))  //输出{String sql="INSERT INTO size VALUES ('"+ss[i]+"','"+jj[i]+"')";            stmt.executeUpdate(sql);ans1[i]=jj[i];out.print(ss[i]);%><br><form  name="form4" method="post" action="fscheck.jsp">请输入答案<input name=<%=daan[i] %> type="text" id="daan"><br/>       <%       }else{i--;}}session.setAttribute("v1", ss);session.setAttribute("v2", ans1);%><input type="submit" value="统计结果"> </form><%}if(Integer.parseInt(weishu)==2){String j=request.getParameter("shuliang");int sl=Integer.valueOf(j);int bi=Integer.valueOf(zuid);String []ss=new String[sl];String daan[] =new String [sl];String s="";int ans=0;String ans1[]=new String[sl];int a[]=new int [sl];int a1[]=new int[sl];int b[]=new int [sl];int b1[]=new int[sl];int flag=0;int flag1=0;int flag2=0;int flag3=0;int c[]=new int [sl];int d[]=new int[sl];int d1[]=new int[sl];int e[]=new int[sl];int fs=Integer.valueOf(fss);int ys=Integer.valueOf(yss);int y=0;int y1=0;int y2=0;for(int i=0;i<sl;i++){String j1=request.getParameter("kuohao");int y3=Integer.valueOf(j1);int c1 []=new int [20000];flag1=0;flag2=0;y=(int)(Math.random()*4+3);//生成数的个数y1=(int)(Math.random()*2);//有无括号y2=(int)(Math.random()*2);//前后a[i]=(int)(Math.random()*(bi-1-1)+1);a1[i]=(int)(Math.random()*(bi-1)+1);b[i]=(int)(Math.random()*(bi-1-1)+1);b1[i]=(int)(Math.random()*(bi-1)+1);c[i]=(int)(Math.random()*4);if((a[i]>=a1[i])||(b[i]>=b1[i])) //判断是否为真分数{flag2=1;}else   //是真分数继续进行{flag2=0;}if(fs==1){flag=0;}if(fs==2)// 没有负数{if(c[i]==1){if((a[i]*b1[i]-a1[i]*b[i])>=0){flag=0;}else{flag=1;}}}if(c[i]==0){s=" + ";}if(c[i]==1){s=" - ";}if(c[i]==2){s=" * ";}if(c[i]==3){if(ys==1){s=" ÷ ";}if(ys==2){if(((a[i]*b1[i])%(a1[i]*b[i]))==0){s=" ÷ ";}else{flag=1;}}}int z=g.gongyue(a[i],a1[i]);int z1=g.gongyue(b[i],b1[i]);a[i]=a[i]/z;a1[i]=a1[i]/z;b[i]=b[i]/z1;b1[i]=b1[i]/z1;c1[i]=(int)(Math.random()*4);ss[i]=a[i]+"/"+a1[i]+s+b[i]+"/"+b1[i];if(y3==1)//有括号生成{for(int  r=0;r<(y-2);r++){y1=(int)(Math.random()*2);//有无括号y2=(int)(Math.random()*2);//前后d[r]=(int)(Math.random()*(bi-1-1)+1);d1[r]=(int)(Math.random()*(bi-1)+1);int z3=g.gongyue(d[r],d1[r]);d[r]=d[r]/z3;d1[r]=d1[r]/z3;if(d[r]>=d1[r]){flag3=1;}else{flag3=0;}if(c1[i]==0){s=" + ";}if(c1[i]==1){s=" - ";}if(c1[i]==2){s=" * ";}if(c1[i]==3){if(ys==1){s=" ÷ ";}if(ys==2){if(y2==0){if((a[i]*b1[i])%(a1[i]*b[i])==0){s=" ÷ ";}elseflag=1;}}}if(y1==0) //随机数生成没有括号情况{if((y2==0)&&(flag3==0)) //加在后面{ss[i]=ss[i]+s+d[r]+"/"+d1[r];}if((y2==1)&&(flag3==0))  //加在前面{ss[i]=d[r]+"/"+d1[r]+s+ss[i];}}if(y1==1) //随机数生成了括号{if((y2==0)&&(flag3==0))  //加在后面{ss[i]="("+ss[i]+")"+s+d[r]+"/"+d1[r];}if((y2==1)&&(flag3==0))  //括号加在前边{ss[i]=d[r]+"/"+d1[r]+s+"("+ss[i]+")";}}for(int i2=0;i2<i;i2++){if(ss[i2]==ss[i])flag1=1;elseflag1=0;}if(flag3!=0)r--;}}if(y3==2)  //没有括号{for(int  r=0;r<(y-2);r++){c1[i]=(int)(Math.random()*4);y1=(int)(Math.random()*2);//有无括号y2=(int)(Math.random()*2);//前后d[r]=(int)(Math.random()*(bi-1-1)+1);d1[r]=(int)(Math.random()*(bi-1)+1);int z4=g.gongyue(d[r],d1[r]);d[r]=d[r]/z4;d1[r]=d1[r]/z4;if(d[r]>=d1[r]){flag3=1;}else{flag3=0;}if(c1[i]==0){s=" + ";}if(c1[i]==1){s=" - ";}if(c1[i]==2){s=" * ";}if(c1[i]==3){if(ys==1){s=" ÷ ";}if(ys==2){if((a[i]*b1[i])%(a1[i]*b[i])==0){s=" ÷ ";}elseflag=1;}}if(y1==1) //没有括号{if((y2==0)&&(flag3==0)) //加在后面{ss[i]=ss[i]+s+d[r]+"/"+d1[r];}if((y2==1)&&(flag3==0)){ss[i]=d[r]+"/"+d1[r]+s+ss[i];}}for(int i2=0;i2<i;i2++){if(ss[i2]==ss[i])flag1=1;elseflag1=0;}if(flag3!=0)r--;} //小for 循环}if((flag==0)&&(flag1==0)&&(flag2==0)&&(flag3==0)){out.print(ss[i]);%><br><form  name="form5" method="post" action="fscheck.jsp">请输入答案<input name=<%=daan[i] %> type="text" id="daan"><br/>       <%      }elsei--;}session.setAttribute("v1", ss);session.setAttribute("v2", ans1);%><input type="submit" value="统计结果"> </form><%}
%>
</body>
</html>

分数核查:

<%@ 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>
<%String[] s1= (String[])session.getAttribute("v1");String[] answer= (String[])session.getAttribute("v2");String[] daan=new String[s1.length];int count=0;//正确答案的个数for(int i=0;i<s1.length;i++){out.print("运算式为:");out.print(s1[i]+"  ");out.print("您的输入结果为:");daan[i]=request.getParameter("name"+i);out.print(daan[i]+"   ");out.print("正确结果为:");out.print(answer[i]);if(daan[i].equals(answer[i])){out.print("恭喜你答对了!");count++;}else{out.print("很遗憾,你答错了!");}out.print("<br>");}out.print("你一共答对的题目数:");out.print(count);%>
</body>
</html>

 三.运行结果截图:

  

4遇到的问题

在编程当中,遇到了很多麻烦,下面来阐述一下。首先,遇到的是怎么将菜单填入的值让自己和java里面用上,后来通过request方法来解决这个问题。还有就是随机数的生成,之前一直用的是Random类来实现随机数的生成,但是在JSP中好像不能直接那么用了,最后用的(int)(Math.random*n)方法。通过定义一个字符串数字,解决了文本框中输入值,和正确结果比对的问题。在有数据库连接方面,如果想在JSP中进行数据库的连接,在java中的驱语句后面还要加上.Instance()才能加载上。而且的Jdbc还要放在lib文件夹下。另外还有一个问题就是,在分数的情况下,执行SQL语句时,例如用1'1/5表示一又五分之时,会有二义性,最后将'改为|.

转载于:https://www.cnblogs.com/ever1961211/p/6664742.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541665.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Java RandomAccessFile seek()方法与示例

RandomAccessFile类seek()方法 (RandomAccessFile Class seek() method) seek() method is available in java.io package. seek()方法在java.io包中可用。 seek() method is used to sets the file pointer position calculated from the starting of this file at which the …

Javascript开发技巧(JS中的变量、运算符、分支结构、循环结构)

一、Js简介和入门 继续跟进JS开发的相关教程。 <!-- [使用JS的三种方式] 1、HTML标签中内嵌JS&#xff08;不提倡使用&#xff09;&#xff1a; 示例&#xff1a;<button οnclick"javascript:alert(你真点啊&#xff01;)">有本事点我呀&#xff01;&#…

android 颜色范围,Android系统颜色的适用范围

###All Clickable Views:ripple effect (Lollipop only) — “colorControlHighlight”###Status Bar:background (Lollipop only) – “colorPrimaryDark”###Navigation Bar:background (Lollipop only) – “android:navigationBarColor”###EditText:underline (unfocused)…

bytevalue_Java Short类byteValue()方法及示例

bytevalue短类byteValue()方法 (Short class byteValue() method) byteValue() method is available in java.lang package. byteValue()方法在java.lang包中可用。 byteValue() method is used to return the value denoted by this Short object converted to type byte (by …

分布式交换机配置备份和还原

1.备份和还原vSphere Distributed Switch配置 1.1导出 vSphere Distributed Switch 配置 可以将 vSphere Distributed Switch 和分布式端口组配置导出到某一文件。该文件保留有效的网络配置&#xff0c;使这些配置能够传输至其他环境。 步骤&#xff1a; 1) 在 vSphere Web Cli…

html自动执行函数,JS 自执行函数原理及用法

js自执行函数&#xff0c;听到这个名字&#xff0c;首先会联想到函数。接下来&#xff0c;我来定义一个函数&#xff1a;function aaa(a,b){return sum a b}定义了一个名为aaa的函数&#xff0c;在里面可以计算两个数的和。如果想执行它&#xff0c;就必须得调用它&#xff0…

java reverse_Java Integer类reverse()方法与示例

java reverse整数类reverse()方法 (Integer class reverse() method) reverse() method is available in java.lang package. reverse()方法在java.lang包中可用。 reverse() method is used to returns the value generated by reversing the order of bits in binary 2s comp…

华为鸿蒙系统好在哪,华为鸿蒙2.0可以替代安卓吗,华为鸿蒙2.0优势在哪

在华为开发者大会上&#xff0c;华为消费业务CEO 余承东&#xff0c;正式发布鸿蒙OS2.0&#xff0c;并宣布华为鸿蒙OS将全面启用全场景生态&#xff0c;并将于2020年12月发布手机版。余承东还表示&#xff0c;明年&#xff0c;华为的智能手机将全面升级&#xff0c;以支持鸿蒙操…

Java GregorianCalendar add()方法与示例

GregorianCalendar类的add()方法 (GregorianCalendar Class add() method) add() method is available in java.util package. add()方法在java.util包中可用。 add() method is used to add the given quantity to the specified GregorianCalendar field (fi). add()方法用于…

JVM(三)——对象的访问定位

JVM&#xff08;三&#xff09;——对象的访问定位创建完对象&#xff0c;到了使用对象的时候&#xff0c;通常声明一个同类型的引用指向该类型的对象&#xff0c;由这个引用来操作对象的字段、方法等。 Object obj new Object();复制代码我们的Java程序需要通过栈上的 refere…

html5滑动删除置顶,html5向左滑动删除特效

html5向左滑动删除特效* {padding: 0;margin: 0;list-style: none;}header {background: #f7483b;border-bottom: 1px solid #ccc}header h2 {text-align: center;line-height: 54px;font-size: 16px;color: #fff}.list-ul {overflow: hidden}.list-li {line-height: 60px;bord…

Java Double类hashCode()方法及示例

双类hashCode()方法 (Double class hashCode() method) hashCode() method is available in java.lang package. hashCode()方法在java.lang包中可用。 hashCode() method is used to return hashcode of the Double-object. hashCode()方法用于返回Double对象的哈希码。 hashC…

Java DataOutputStream size()方法及示例

DataOutputStream类的size()方法 (DataOutputStream Class size() method) size() method is available in java.io package. size()方法在java.io包中可用。 size() method is used to return the size of this stream or in other words, we can say it returns the value of…

html怎样让列表向下移动,Html无序列表ul控件实现行上下移动.

new document // 创建一个ulvar ul document.createElement("ul");ul.id "oList";// 创建divvar div document.getElementById(mergeCase);// 把ul放置到div中div.appendChild(ul);// 遍历所有的li条目function trace(){var strTest "";for …

创建laravel项目

下载项目到本地 git clone https://github.com/251068550/LaraBlog.gitcompoer安装 cd LaraBlog composer install如果composer install安装很慢&#xff0c;推荐安装国内镜像 执行 composer config -g repo.packagist composer https://packagist.phpcomposer.com 配置.env文件…

Java ArrayList removeRange()方法与示例

ArrayList类removeRange()方法 (ArrayList Class removeRange() method) removeRange() method is available in java.util package. removeRange()方法在java.util包中可用。 removeRange() method is used to remove the elements whose range is between st_in(start index)…

Spring注释事务失效及解决办法

如果带上事务&#xff0c;那么用annotation方式的事务注解和bean配置&#xff0c;事务会失效&#xff0c;要将service bean配置到xml文件中才行 在主容器中&#xff08;applicationContext.xml&#xff09;&#xff0c;将Controller的注解排除掉 <context:component-scan …

html5画分形图形,2.5 绘制透明图形 - HTML5 Canvas 实战

对于需要图形分层的应用&#xff0c;经常需要处理透明度。本节&#xff0c;我们将学习如何使用全局透明度设置图形的透明度。图2-5 绘制透明图形绘制步骤按照以下步骤&#xff0c;在一个不透明的矩形之上&#xff0c;绘制一个透明的圆&#xff1a;1. 定义2D画布上下文&#xff…

计算机网络子网划分_子网划分和超网| 计算机网络

计算机网络子网划分1)子网划分 (1) Subnetting) Subnetting is a concept of diving a block of addresses into sub-blocks of addresses. During the era of classful addressing (as it’s obscured now), subnetting was introduced. Say, an organization is granted a la…

html5录音功能代码,recorder.js 基于 HTML5 实现录音功能

recorder.js 基于 HTML5 实现录音功能2020-06-23 01:49:56recorder.jsmicrophone基于HTML5的录音功能&#xff0c;输出格式为mp3文件。前言完全依赖H5原生API所涉及的API&#xff1a;WebRTC、AudioContext、Worker、Video/Audio API、Blob、URL兼容性Chrome、FF、Edge、QQ、360…