我只得到值1的随机偶数。值1和2都需要它。有人可以教我如何解决它吗?
我正在使用threadlocalrandom
public void setQuestion(){
Random rand = new Random();
int value1 = ThreadLocalRandom.current().nextInt(10,100);
int value2 = ThreadLocalRandom.current().nextInt(2,20);
int randomquestion = rand.nextInt(2);
if (randomquestion == 1){
question.setText("What is"+ value1 + "+" + value2 +" ? ");
expected= "" + (value1 + value2);
}else if (randomquestion == 2){
question.setText("What is"+value1 +"-" + value2 +" ? ");
expected="" + (value1 - value2);
}else if (randomquestion == 3){
question.setText("What is"+value1+ "*" + value2 +" ? ");
expected ="" + (value1*value2);
}else {
question.setText("What is"+value1+"/" + value2 +"?");
expected="" + (value1/value2);
}
sumanswer.setText("Total Score ="+ correctanswer +"Correct and"+ wronganswer + "Wrong");
}
我希望两个值都可以是随机偶数。
答案 0 :(得分:1)
试试看
Random r = new Random();
int value1 = r.nextInt(100-10) + 10;
int value2 = r.nextInt(20-2) + 2;