Some times in result I get an unexpected answer for example if the Question is 10-8 the program is giving -9 as a correct answer.
public void questionAnswerGenerator(){
Random random = new Random();
int a = random.nextInt(21);
int b = random.nextInt(21);
if (a >= b) {
questionBoard.setText(Integer.toString(a) + " - " + Integer.toString(b));
}else {
questionAnswerGenerator();
}
locationOfCorrectAnswer = random.nextInt(4);
answer.clear();
int incorrectAnswer;
for (int i=0; i<4; i++){
if (i == locationOfCorrectAnswer) {
answer.add(a - b);
}else {
incorrectAnswer = random.nextInt(41);
while (incorrectAnswer == a - b){
incorrectAnswer = random.nextInt(41);
}
answer.add(incorrectAnswer);
}
}
Aucun commentaire:
Enregistrer un commentaire