我正在编写一个程序,询问您是否要进行加法,减法,乘法和除法。然后它询问了多少问题。我有一切工作,但司。我想确保在进行除法问题时不会有余数。我不知道如何做这项工作。
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 :(得分:0)
您专门选择 提醒的数字。你可以在有提醒时循环:
} while (num1 % num2 != 0);
然而,你根本不需要循环。如果选择第二个操作数和答案,则可以计算第一个操作数:
num2 = (int) (Math.random() *10);
compAnswer = (int) (Math.random() * 10);
num1 = num2 * compAnswer;