2014-09-25 34 views
0

我正在製作一個程序,它會詢問您是否要執行加法,減法,乘法和除法。然後它會詢問有多少問題。我有一切工作,但司。我想確保在分區問題時不會有剩餘部分。我不知道如何做這項工作。數學:劃分問題發生器

 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 + 
     "."); } 

回答

0

你特別挑選號碼那裏提醒。你可以循環,而有提醒,而不是:

} while (num1 % num2 != 0); 

但是,你將不需要循環。如果選擇第二個操作數和答案,則可以計算第一個操作數:

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

num1 = num2 * compAnswer;