值1和值2的偶数

时间:2019-06-16 11:16:14

标签: java android

我只得到值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");
}

我希望两个值都可以是随机偶数。

1 个答案:

答案 0 :(得分:1)

试试看

Random r = new Random();
int value1 = r.nextInt(100-10) + 10;
int value2 = r.nextInt(20-2) + 2;