【问题标题】: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 +
      "."); }

【问题讨论】:

    标签: math integer-division


    【解决方案1】:

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

    } while (num1 % num2 != 0);
    

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-26
      • 2017-04-10
      • 1970-01-01
      相关资源
      最近更新 更多