数学:除法问题生成器

Posted

技术标签:

【中文标题】数学:除法问题生成器【英文标题】:Math: Division Problems Generator 【发布时间】:2014-09-25 21:46:38 【问题描述】:

我正在制作一个程序,询问您是否想做加法、减法、乘法和除法。然后它会询问多少个问题。除了除法之外,我一切正常。我想确保在做除法问题时不会有余数。我不知道如何使这项工作。

      else if (player==4) 

      System.out.print("How many questions would you like?-->"); player =
      in.nextInt(); numQuestions= player;


      do

      //question
          do 
              do
          num1 = (int) (Math.random() * 100);
          num2 = (int) (Math.random() *10);

              while (num2 > num1);
           while (num1 % num2 == 0);


              compAnswer = num1 / num2;



                  System.out.println(num1+" / " + num2 + "=");                  
                  System.out.print("What's your answer? -->");
                  player = in.nextInt();
                    if (player == compAnswer) 
                        System.out.println(" That's right, the answer is "
                                + compAnswer);
                        System.out.println("");
                        score++;
                     else 
                        System.out.println("That's wrong! The answer was "
                                + compAnswer);
                        System.out.println("");                     

                    
            //x++;


      while( x < numQuestions + 1 );

      System.out.println("");
      System.out.println("Thanks for playing! Your score was " + score +
      "."); 

【问题讨论】:

【参考方案1】:

您正在专门挑选有 提醒的号码。您可以在有提醒时循环播放:

 while (num1 % num2 != 0);

但是,您根本不需要循环。如果你选择第二个操作数和答案,你可以计算第一个操作数:

num2 = (int) (Math.random() *10);
compAnswer = (int) (Math.random() * 10);

num1 = num2 * compAnswer;

【讨论】:

以上是关于数学:除法问题生成器的主要内容,如果未能解决你的问题,请参考以下文章

迷宫生成 - 递归除法(它是如何工作的?)

递归除法迷宫生成算法

关于CRC基础的几个问题

整数除法的数学运算

怎么求最小生成树 (离散数学 图论)

软件工程个人作业02