式子生成终极版本(web)

设计思路:在页面一中输入是选择整数还是分数

              再在第二个页面中输入相应参数

              用request语句在第三个页面中获取之后就跟java版本一样,根据参数输出结果,并且根据输入结果判断正确性。

源代码:               

 webpage1

 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          <%int i=1; %>
11          <form name="form" method="post" action="Webpage2.jsp">
12          
13                                 是整数还是分数计算:整数<input type="radio" value="1" name="leixing" checked>
14                                 分数<input type="radio" value="2" name="leixing"><br>
15                        
16          <input type="hidden" name="demp" value="<%=i%>">        
17          <input type="submit" value="提交" name="submit">
18          </form>
19 </body>
20 </html>

webpage2

 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          <%int i=1;%>
11          <form name="form" method="post" action="Webpage3.jsp">
12          <%
13          String leixing_string=request.getParameter("leixing");
14          int leixing_int=Integer.parseInt(leixing_string);//从上一页获得参数并根据参数进行判断
15          if(leixing_int==1)
16          {
17          %>
18                                  生成数字的最大范围<input type="text" name="number_zuidafanwei"> <br>
19                                  
20                                  生成数字的最小范围<input type="text" name="number_zuixiaofanwei"> <br>
21                                  
22                                  生成多少个式子<input type="text" name="number_amount"> <br>
23                                  
24                                 是否有乘除法:有<input type="radio" value="1" name="tiaojian_chengchu" checked>
25                                 没有<input type="radio" value="2" name="tiaojian_chengchu"><br>
26          <%
27          }
28          else if(leixing_int==2)
29          {
30          %>
31                                 生成多少个式子<input type="text" name="number_amount"> <br>
32                                 
33                                 是否有乘除法:有<input type="radio" value="1" name="tiaojian_chengchu" checked>
34                                 没有<input type="radio" value="2" name="tiaojian_chengchu"><br>
35                                 
36                                 加减是否能得负数:可以<input type="radio" value="1" name="tiaojian_fushu" checked>
37                                 不可以<input type="radio" value="2" name="tiaojian_fushu"><br>
38          <%
39          }
40          %>
41          <input type="hidden" name="i" value=leixing>
42          <input type="hidden" name="demp" value="<%=i%>">        
43          <input type="submit" value="提交" name="submit">
44          </form>
45 </body>
46 </html>

webpage3

  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>Insert title here</title>
  8 </head>
  9 <body>
 10 <%int i=1;%>
 11 <%
 12 class MyStack 
 13 {
 14     int top;    
 15     int maxSize;   
 16     int array[];
 17     public MyStack(int maxSize) 
 18     {  
 19         this.maxSize = maxSize;  
 20         array = new int[maxSize];  
 21         top = 4;  
 22     } 
 23     
 24     public MyStack(){}
 25 
 26     public void push(int value) 
 27     {  
 28         array[++top] = value;  
 29     }
 30     
 31     public int pop() 
 32     {  
 33         
 34         return array[top--]; 
 35         
 36     }
 37     
 38     public int getTopvalue() 
 39     {  
 40         return array[top];  
 41     }
 42     
 43     public int getTopvalue2() 
 44     {  
 45         int a;
 46         a=top--;
 47         top++;//使指针复原
 48         return array[a];  
 49     }
 50     
 51     public int isEmpty() 
 52     {  
 53         return top ;  
 54     }
 55     
 56     public boolean isFull() 
 57     {  
 58         return top == maxSize - 1;  
 59     }
 60 }
 61 
 62 class Main 
 63 {
 64     int [][] z = new int[30][20];//定义二维数组
 65     int [][] x = new int[30][11];//定义二维数组    
 66     
 67     public  int output(int a,int b,int c,int d,int e)//分数输出
 68     {
 69         String fenshushuchu="";
 70         for(int i = a;i > 1;i--)
 71         {
 72             if(a % i == 0 && b % i == 0)
 73             {
 74                 a = a / i;
 75                 b = b / i;
 76                 break;
 77             }
 78         }
 79         for(int i = c;i > 1;i--)
 80         {
 81             if(c%i == 0 && d % i == 0)
 82             {
 83                 c = c / i;
 84                 d = d / i;
 85                 break;
 86             }
 87         }
 88         switch(e)
 89         {
 90              case 0 : fenshushuchu="("+ a + "/"+ b + ")" + "+" + "(" + c + "/" + d + ")" + "=?";
 91              case 1 : fenshushuchu="("+ a + "/"+ b + ")" + "-" + "(" + c + "/" + d + ")" + "=?";
 92              case 2 : fenshushuchu="("+ a + "/"+ b + ")" + "*" + "(" + c + "/" + d + ")" + "=?";
 93              case 3 : fenshushuchu="("+ a + "/"+ b + ")" + "/" + "(" + c + "/" + d + ")" + "=?";
 94         }
 95         %>
 96         式子为:<%=fenshushuchu %>>
 97         <%
 98         return 1;
 99     }
100     public  int fenshu_zhengquejieguo(int a,int b,int c,int d,int e)
101     {
102         int jieguo = 0;
103         switch(e)
104         {
105              case 0: jieguo=(a * d + c * b) / (b * d);break;
106              case 1: jieguo=(a * d - c * b) / (b * d);break;
107              case 2: jieguo=(a * c) / (b * d);break;
108              case 3: jieguo=(a * d) / (b * c);break;
109         }
110         return jieguo;
111     }
112     public  int zhengshu_zhengquejieguo(int a[])
113     {
114         MyStack Fuhao = new MyStack(20);
115         MyStack Shuzi = new MyStack(20);
116         int e,c,p,e2,q;
117         for(int i = 6;i < 13;i++)
118         {
119             if(i%2 == 1)//如果是符号压入符号栈
120             {
121                 Fuhao.push(a[i]);
122             }
123             else//否则压入数字栈
124             {
125                 Shuzi.push(a[i]); 
126             }
127 
128             if(i > 7 &&Fuhao.getTopvalue() > 1 &&  i % 2 == 0)//如果从左向右遇见乘除法就直接执行
129             {
130                 e = Fuhao.pop();
131                 c = Shuzi.pop();
132                 p = Shuzi.pop();
133                 switch(e)
134                 {
135                      case 2: Shuzi.push(c*p);break;
136                      case 3: Shuzi.push(p/c);break;
137                 }
138             }
139             if(i > 9 && Fuhao.getTopvalue() < 2 &&  Fuhao.getTopvalue2()< 2  && i % 2 == 0 && Fuhao.isEmpty() > 5)//如果遇见连续的两个加减法执行第一个
140             {
141                 e = Fuhao.pop();
142                 e2 = Fuhao.pop();
143                 c = Shuzi.pop();
144                 p = Shuzi.pop();
145                 q = Shuzi.pop();
146                 switch(e2)
147                 {
148                      case 0: Shuzi.push((q + p));break;
149                      case 1: Shuzi.push((q - p));break;
150                 }
151                 Shuzi.push(c);
152                 Fuhao.push(e);
153             }
154         }
155 
156         if(Shuzi.isEmpty() > 4)//最终肯定会剩下一组数还有最后一次加减运算
157         {
158              e = Fuhao.pop();
159              c = Shuzi.pop();
160              p = Shuzi.pop();
161 
162              switch( e )
163              {
164                   case 0: Shuzi.push((p + c));break;
165                   case 1: Shuzi.push((p - c));break;
166              }
167         }
168 
169         return Shuzi.getTopvalue();
170 
171     }
172 
173     public  int panduanchongfu(int a[],int ma,int mi,int y)
174     {
175     //---------------------------------------------用来判断是不是完全相同-----------------------------------------------------
176         int m = 1;
177         while(m == 1)
178         {
179             for(int j = 0;j < y;j++)
180             {
181                 if(a[0]==z[j][0]&&a[1]==z[j][1]&&a[2]==z[j][2]&&a[3]==z[j][3]&&a[4]==z[j][4]&&a[5]==z[j][5]&&a[6]==z[j][6])
182                 {
183                     a[0] = mi + (int)(Math.random()*ma);
184                     z[y][0] = a[0];
185 
186                     a[1] = mi + (int)(Math.random()*ma);
187                     z[y][1] = a[1];
188                     break;
189                 }
190 
191                 if( j == ( y - 1 ) )
192                 {
193                     m = 0;
194                 }
195             }
196         }
197     //----------------------------------------------判断加法出现时候是不是完全相同------------------------------------------------------------
198         while(m == 1)
199         {
200             for(int j = 0;j < y;j++)
201             {
202                 if(a[1]==0&&a[3]==z[j][3]&&a[4]==z[j][4]&&a[5]==z[j][5]&&a[6]==z[j][6]&&a[0]==a[2]&&a[3]<2)//加法在第一位,并且旁边两个数换了位置
203                 {
204                     a[0] = mi + (int)(Math.random()*ma);
205                     z[y][0] = a[0];
206                     break;
207                 }
208 
209                 if( j == ( y - 1 ) )
210                 {
211                     m = 0;
212                 }
213             }
214         }
215     //----------------------------------------------判断乘法出现时候是不是完全相同------------------------------------------------------------
216         /*while(m == 1)
217         {
218             for(int j = 0;j < y;j++)
219             {
220                 
221 
222                 if( j == ( y - 1 ) )需要注意,这几种情况  一个乘号 1.在第一位 2*3 和 3*2 2.在第二位 前边没有乘除法 3.在第三位,第二位没有乘除法
223                 {                                         两个乘号 1.在前两个 1*2*3 和 3*2*1 和 2*3*1 等六种情况 2.在后两个,前边不是乘除法
224                     m = 0;                                三个乘号 
225                 }
226             }
227         }*/
228     //---------------------------------------------加法和乘法除法相邻出现并且重复---------------------------
229         /*加法连接乘除法 1+2*3 == 2*3+1
230         */
231         return 1;
232     }
233 
234     public  int tiaojianpanduan(int a[],int y,int ma,int mi)//整数输出
235     {
236         for(int i = 6;i < 13;i++)
237         {
238             if(i%2 == 0)//挑出数字,如果直接筛选出符号那么不能修改之前的数字
239             {
240     //---------------------------------------------------------------------------------------------------------------------------------------
241                 while(a[i] == 0)//判断被除数为0的情况
242                 {
243                     while(i > 6 && a[i - 1] == 3)
244                     {
245                         a[i] = mi + (int)(Math.random()*ma);
246                         z[y][i] = a[i];//更新原来数组
247                     }
248                 }
249                 if(a[ i + 1 ] == 2 )//出现除法前边有乘法的情况,首先计算出乘法的结果
250                 {//并且根据概率更新除法参与运算数的情况有可能永远不能实现结果为真分数,所以更新乘法参与运算数
251                     if(a[ i + 3 ] == 3)
252                     {
253                         while(a[i] * a[i+2] >= a[i+4])
254                         {
255                             a[i+2] = mi + (int)(Math.random()*ma);
256                             z[y][i+2] = a[i+2];//更新原来数组
257                         }
258                     }
259                 }
260                 if(a[i+1] == 3 && a[i-1] != 2)//有除法,其中包括只有一个除法,还有连续好几个除法,但是通过改变后一个数的规律可以有效的解决这个问题
261                 {
262                         while(a[i] >= a[i + 2])
263                         {
264                             a[i+2] = mi + (int)(Math.random()*ma);
265                             z[y][i+2] = a[i+2];//更新原来数组
266                         }
267                 }
268     //--------------------------------------此上是处理出现除法的情况,此下是减法---------------------------------------------------------------
269                 if(a[i+1]==1)//出现减法的情况
270                 {
271                     if(i + 1 ==11 && a[i-3]==3 && a[i-1]==2 && a[i-4]/a[i-2]*a[i] < a[i+2])//减法在最后一个符号位置,并且前边是除法连接乘法
272                     {
273                         while(a[i-4]/a[i-2]*a[i]<mi)//前边计算出来的数字之和小于随机生成数的最小值,那么就更新最后一个数字和乘法的后一个数字
274                         {
275                             a[i] = mi + (int)(Math.random()*ma);
276                             a[i+2] = mi + (int)(Math.random()*ma);
277                             z[y][i] = a[i];//更新原来数组
278                             z[y][i+2] = a[i+2];//更新原来数组
279 
280                         }
281                         while(a[i-4]/a[i-2]*a[i] >= mi)//如果大于最小值,那么只需要更新减数
282                         {
283                             a[i+2] = mi + (int)(Math.random()*ma);
284                             z[y][i+2] = a[i+2];//更新原来数组
285                         }
286                     }
287                     if(a[i-1]==3 && i+1==9)//除法出现在减法前边一个符号,将减法变为加法.只有减法在第二个符号时有效
288                     {
289                         a[i+1]=0;
290                         z[y][i+1] = a[i+1];//更新原来数组
291                     }
292                     //此上两种情况是处理除法和减法同时出现并且互相影响的情况
293                 //减号附近有没有乘除法,提前计算
294                     switch(i+1)
295                     {
296                         case 7:
297                                //减法在第一位的情况
298                                if(a[i+3]==2 && a[i+5]<2)//- * _ 因为前一步已经将除法得数化为真分数,所以不用考虑除法的情况
299                                {
300                                     while(a[i]-a[i+2]*a[i+4]<0)
301                                     {
302                                         a[i+2] = mi + (int)(Math.random()*ma);
303                                         z[y][i+2] = a[i+2];//更新原来数组
304                                         a[i+4] = mi + (int)(Math.random()*ma);
305                                         z[y][i+4] = a[i+4];//更新原来数组
306                                     }
307                                }
308                                if(a[i+3]==2 && a[i+5]==2)//- * *同上步解释,不用考虑先乘后初的情况
309                                {
310                                     while(a[i]-a[i+2]*a[i+4]*a[i+6]<0)
311                                     {
312                                         a[i+2] = mi + (int)(Math.random()*ma);
313                                         z[y][i+2] = a[i+2];//更新原来数组
314                                         a[i+4] = mi + (int)(Math.random()*ma);
315                                         z[y][i+4] = a[i+4];//更新原来数组
316                                         a[i+6] = mi + (int)(Math.random()*ma);
317                                         z[y][i+6] = a[i+6];//更新原来数组
318                                     }
319                                }
320                                if(a[i+3]==2 && a[i+5]==2)//- / *
321                                {
322                                     while(a[i]-a[i+2]/a[i+4]*a[i+6]<0)
323                                     {
324                                         a[i+2] = mi + (int)(Math.random()*ma);
325                                         z[y][i+2] = a[i+2];//更新原来数组
326                                         a[i+4] = mi + (int)(Math.random()*ma);
327                                         z[y][i+4] = a[i+4];//更新原来数组
328                                         a[i+6] = mi + (int)(Math.random()*ma);
329                                         z[y][i+6] = a[i+6];//更新原来数组
330                                     }
331                                }break;
332                         case 9://减法在第二位的情况
333                             if(a[i-1]==2&&a[i+3]==2)//* - *
334                             {
335                                 while(a[i-2]*a[i]<a[i+2]*a[i+4])
336                                 {
337                                     a[i+2] = mi + (int)(Math.random()*ma);
338                                     z[y][i+2] = a[i+2];//更新原来数组
339                                     a[i+4] = mi + (int)(Math.random()*ma);
340                                     z[y][i+4] = a[i+4];//更新原来数组
341                                 }
342                             }
343                             if(a[i+3]==2 && a[i-1]==0)//+ - *
344                             {
345                                 while( ( a[i-2] + a[i] ) < ( a[i+2] * a[i+4] ) )
346                                 {
347                                     a[i+2] = mi + (int)(Math.random()*ma);
348                                     z[y][i+2] = a[i+2];//更新原来数组
349                                     a[i+4] = mi + (int)(Math.random()*ma);
350                                     z[y][i+4] = a[i+4];//更新原来数组
351                                 }
352                             }
353                             if(a[i+3]==2 && a[i-1]==1)//- - *
354                             {
355                                 while( ( a[i-2] - a[i] ) < ( a[i+2] * a[i+4] ) )
356                                 {
357                                     a[i+2] = mi + (int)(Math.random()*ma);
358                                     z[y][i+2] = a[i+2];//更新原来数组
359                                     a[i+4] = mi + (int)(Math.random()*ma);
360                                     z[y][i+4] = a[i+4];//更新原来数组
361                                 }
362                             }
363                             if(a[i+3]<2 && a[i-1]==2)//* - _
364                             {
365                                 while(a[i-2]*a[i]<a[i+2])
366                                 {
367                                     a[i+2] = mi + (int)(Math.random()*ma);
368                                     z[y][i+2] = a[i+2];//更新原来数组
369                                 }
370                             }
371                         case 11://减法在第三位的情况
372                             if(a[i-3]==2&&a[i-1]==2)//* * -
373                             {
374                                 while(a[i-4]*a[i-2]*a[i]<a[i+2])
375                                 {
376                                     a[i+2] = mi + (int)(Math.random()*ma);
377                                     z[y][i+2] = a[i+2];//更新原来数组
378                                     a[i] = mi + (int)(Math.random()*ma);
379                                     z[y][i] = a[i];//更新原来数组
380                                 }
381                             }
382                             if(a[i-3]==0&&a[i-1]==2)//+ * -
383                             {
384                                 while(a[i-4]+a[i-2]*a[i]<a[i+2])
385                                 {
386                                     a[i+2] = mi + (int)(Math.random()*ma);
387                                     z[y][i+2] = a[i+2];//更新原来数组
388                                     a[i] = mi + (int)(Math.random()*ma);
389                                     z[y][i] = a[i];//更新原来数组
390                                 }
391                             }
392                             if(a[i-3]==1&&a[i-1]==2)//- * -
393                             {
394                                 while(a[i-4]-a[i-2]*a[i]<a[i+2])
395                                 {
396                                     a[i+2] = mi + (int)(Math.random()*ma);
397                                     z[y][i+2] = a[i+2];//更新原来数组
398                                 }
399                             }
400                             if(a[i-3]==0&&a[i-1]==3)//+ / -
401                             {
402                                 while(a[i-4]+a[i-2]/a[i]<a[i+2])
403                                 {
404                                     a[i+2] = mi + (int)(Math.random()*ma);
405                                     z[y][i+2] = a[i+2];//更新原来数组
406                                     a[i] = mi + (int)(Math.random()*ma);
407                                     z[y][i] = a[i];//更新原来数组
408                                 }
409                             }
410                             if(a[i-3]==1&&a[i-1]==3)//- / -
411                             {
412                                 while(a[i-4]-a[i-2]/a[i]<a[i+2])
413                                 {
414                                     a[i+2] = mi + (int)(Math.random()*ma);
415                                     z[y][i+2] = a[i+2];//更新原来数组
416                                 }
417                             }
418                     }
419                     while(a[i]<a[i+2])
420                     {
421                         a[i+2] = mi + (int)(Math.random()*ma);
422                         z[y][i+2] = a[i+2];//更新原来数组
423                     }
424                 }
425             }
426         }
427         return 1; 
428     }
429 
430     public  int shuchu(int a[],int y,int ma,int mi)//整数输出
431     {
432         String s="";
433         for(int i = 6;i < 13;i++)
434         {
435             if(i%2 == 0)//挑出数字
436             {
437                 s=s+a[i];
438             }
439             else
440             {
441                 switch(a[i])
442                 {
443                 
444                     case 0: s=s+"+";break;
445                     case 1: s=s+"-";break;
446                     case 2: s=s+"*";break;
447                     case 3: s=s+"/";break;
448                 }
449             }
450         }
451         
452         %>
453         
454         整数四则运算输出<%=s %>
455         
456         <%
457         
458         return 1; 
459     }
460     
461     public  void main(String[] args)
462     {
463         int[] suijishu =new int [20];
464         int y = 0,p = 0,m=1;
465         int number_amount = 0,number_jisuanshileixing = 0,number_daduishu=0;
466         int ma = 0,mi = 0;
467         int tiaojian_cheng = 0,tiaojian_jia = 0;
468         int kehu_jieguo = 0;
469         String str=request.getParameter("leixing");
470         number_jisuanshileixing=Integer.parseInt(str);
471         if(number_jisuanshileixing == 1)
472         {
473             str=request.getParameter("number_zuidafanwei");
474             ma=Integer.parseInt(str);
475             str=request.getParameter("number_zuixiaofanwei");
476             mi=Integer.parseInt(str);
477             str=request.getParameter("number_amount");
478             number_amount=Integer.parseInt(str);
479             str=request.getParameter("tiaojian_chengchu");
480             tiaojian_cheng=Integer.parseInt(str);
481             for(int i = 0;i < number_amount;i++)
482             {
483                 
484                 %>
485                 
486                 题目 <%=i+1 %>为:
487                 
488                 <%
489                 
490                 for(int i1 = 6 ; i1 < 13 ; i1++)//生成随机数还有符号
491                 {
492                     if(i1%2==0)
493                     {
494                         suijishu[i1]= mi + (int)(Math.random()*ma);
495                     }
496                     else
497                     {
498                         suijishu[i1]= (int)(Math.random()* 4 );//产生加减乘除四种情况
499                         if(tiaojian_cheng == 0)
500                         {
501                             suijishu[i1]= (int)(Math.random()* 2 );
502                         }
503                     }
504                     z[y][i1] = suijishu[i1];
505                 }
506 
507                 tiaojianpanduan(suijishu,y,ma,mi);
508 
509                 if(y > 0)
510                 {
511                      panduanchongfu(suijishu,ma,mi,y);
512                 }
513 
514                 y++;
515 
516                 shuchu(suijishu,y,ma,mi);
517                 %>
518                 请输入正确结果:<input type="text" name="number_kehujieguo"> <br>
519                 <%
520                 int number_jituo=zhengshu_zhengquejieguo(suijishu);
521                 str=request.getParameter("number_kehujieguo");
522                 kehu_jieguo=Integer.parseInt(str);
523                 if(kehu_jieguo == number_jituo)
524                 {
525                     number_daduishu++;
526                     %>
527                     输入正确!结果为<%=number_jituo %>
528                     <%
529                 }
530                 else
531                 {
532                     %>
533                     输入错误!结果为<%=number_jituo %>
534                     <%
535                 }
536              }
537             %>
538             您一共答对了<%=number_daduishu %>道题!
539             <%
540         }
541         else
542         {
543             str=request.getParameter("number_amount");
544             number_amount=Integer.parseInt(str);
545             str=request.getParameter("tiaojian_chengchu");
546             tiaojian_cheng=Integer.parseInt(str);
547             str=request.getParameter("tiaojian_fushu");
548             tiaojian_jia=Integer.parseInt(str);
549 
550             for(int i=0;i<number_amount;i++)
551             {
552                 int frist_fenzi=(int)(Math.random()*100);
553                 int first_fenmu=(int)(Math.random()*100);
554                 int second_fenzi=(int)(Math.random()*100);
555                 int second_fenmu=(int)(Math.random()*100);
556 
557                 int fuhao=(int)(Math.random()*4);
558                 if(p>0)
559                 {
560                     while(m==1)
561                     {
562                         for(int j=0;j<p+1;j++)
563                         {
564                             if(frist_fenzi==x[j][1]&&first_fenmu==x[j][2]&&second_fenzi==x[j][3]&&second_fenmu==x[j][3]&&fuhao==x[j][3])
565                             {
566                                 frist_fenzi=(int)(Math.random()*100);
567                                 second_fenzi=(int)(Math.random()*100);
568                                 break;
569                             }
570                             if(j==p)
571                             {
572                                 m=0;
573                             }
574                         }
575                      }
576                 }
577 
578                 x[p][1]=frist_fenzi;
579                 x[p][2]=first_fenmu;
580                 x[p][3]=second_fenzi;
581                 x[p][4]=second_fenmu;
582                 if(tiaojian_cheng == 0)//处理有无乘除法
583                 {
584                     fuhao=(int)(Math.random()*2);
585                 }
586 
587                 x[p][5]=fuhao;
588 
589                 p++;
590 
591                 if(first_fenmu==0)//去掉分母为零的情况
592                 {
593                  first_fenmu=(int)(Math.random()*100);
594                 }
595                 if(second_fenmu==0)
596                 {
597                   second_fenmu=(int)(Math.random()*100);
598                 }
599 
600                 if(frist_fenzi>first_fenmu)//调整为真分数
601                 {
602                     int x;
603                     x=first_fenmu;
604                     first_fenmu=frist_fenzi;
605                     frist_fenzi=x;
606                 }
607 
608                 if(second_fenzi>second_fenmu)//调整为真分数
609                 {
610                     int x;
611                     x=second_fenzi;
612                     second_fenzi=second_fenmu;
613                     second_fenmu=x;
614                 }
615 
616                 switch(fuhao)
617                 {
618                     case 0: output(frist_fenzi,first_fenmu,second_fenzi,second_fenmu,fuhao);break;
619             
620                     case 1: 
621                         if(tiaojian_jia==0)
622                             {
623                                 while(((double)(frist_fenzi/first_fenmu)-(double)(second_fenzi/second_fenmu))<0)
624                                 {
625                                    frist_fenzi=(int)(Math.random()*100);
626                                    second_fenzi=(int)(Math.random()*100);
627                                 }
628                             }
629                         output(frist_fenzi,first_fenmu,second_fenzi,second_fenmu,fuhao);break;
630              
631                     case 2: output(frist_fenzi,first_fenmu,second_fenzi,second_fenmu,fuhao);break;
632             
633                     case 3: output(frist_fenzi,first_fenmu,second_fenzi,second_fenmu,fuhao);break;
634              
635                 }
636                 %>
637                 请输入正确结果:<input type="text" name="number_kehujieguo"> <br>
638                 <%
639                 str=request.getParameter("number_kehujieguo");
640                 kehu_jieguo=Integer.parseInt(str);
641                 int number_jituo=fenshu_zhengquejieguo(frist_fenzi,first_fenmu,second_fenzi,second_fenmu,fuhao);
642                 if(kehu_jieguo==number_jituo)
643                 {
644                     %>
645                     输入正确!正确结果为<%=number_jituo %>
646                     <%
647                     number_daduishu++;
648                 }
649                 else
650                 {
651                     %>
652                     输入错误!正确结果为<%=number_jituo %>
653                     <%
654                 }
655                 m=1;
656              }
657             %>
658             您一共答对了<%= %>number_daduishu%>道题
659             <%
660         }
661         System.exit(0);
662     }
663     
664 } 
665 %>
666 </body>
667 </html>

 结果截图:

 

posted on 2016-04-10 18:07  火影不火  阅读(263)  评论(0编辑  收藏  举报