2014-09-25 2 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;