【发布时间】: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