式子生成终极版(java)

 
整体设计思想:
  1.宏定义两个二维数组,作为整数和分数计算的储存单位
   
  2.随机生成数字,符号用0123代替。
   
  3.在进栈前先根据if条件判断生成函数中不符合要求的各个条件,然后更新更新宏定义下的数组。
   
  4.在shuchu函数里进行输出。输出具体方法就是根据奇数为符号,偶数为数字的规律数字进行直接输出,符号通过判断输出
   
  5.在jieguojisuan函数中进行计算,方法为应用栈,建立两个栈,一个为数字栈一个为符号栈,计算思想就是遇见两个连续的加减法就计算前一个,遇见乘
  除法就直接计算。计算的细节就是,将数字栈的两个数字和符号栈的一个符号出栈,然后进行计算,将结果压回数字栈。
   
  最终版本实现的功能和实现方法如下
  1.能够实现四则混合运算
  解决方法:将数组扩展,储存多个计算数字。然后根据随机生成的数字生成式子。
   
  2.能够实现计算结果判断
  解决方法:应用栈的思想,计算结果
   
  3.除法生成数字都为真分数,减法得数不能为负数
  解决方法:列举出来具体情况
   
  4.生成随机数字
  应用时间函数,随机生成数字
  如下生成在mi在ma之间的随机整数
  srand((unsigned)time(NULL));
  a[i+2] = rand() % ma + mi;
   
  5.能够判断重复
  只能判断完全重复
 

源代码:

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

结果截图:

整数部分:

分数部分:

 

结果分析:数据,消息都是通过通知框输入输出。

 总结:还有功能尚未实现,而且实现的功能也不尽完美。

比如条件控制处不能够产生负数,是利用暴力穷举,而没有特殊的办法。

原文地址:https://www.cnblogs.com/sisi-job/p/5374764.html