gpt4 book ai didi

java - 打乱数组列表后,如何在数组列表中跟踪正确答案?

转载 作者:行者123 更新时间:2023-12-02 08:09:13 25 4
gpt4 key购买 nike

代码:

       private void getAnswers(int Type) {
/*
* Getting answers here
*/
//int randomValue = random(4);
try {
String answers_list[][] = {
{"Answer 1-1", "Answer 2-1", "Answer 3-1", "Answer 4-1"},
{"Answer 1-2", "Answer 2-2", "Answer 3-2", "Answer 4-2"},
{"Answer 1-3", "Answer 2-3", "Answer 3-3", "Answer 4-3"},
{"Answer 1-4", "Answer 2-4", "Answer 3-4", "Answer 4-4"},
{"Answer 1-5", "Answer 2-5", "Answer 3-5", "Answer 4-5"}} ;
//answer1.setText(answers_list[Type][randomValue+1 > 3 ? (randomValue+0)-4 : randomValue+0]);
//answer2.setText(answers_list[Type][randomValue+2 > 3 ? (randomValue+1)-3 : randomValue+1]);
//answer3.setText(answers_list[Type][randomValue+3 > 3 ? (randomValue+2)-2 : randomValue+2]);
//answer4.setText(answers_list[Type][randomValue+0 > 3 ? (randomValue+3)-4 : randomValue+3]);
Collections.shuffle(Arrays.asList(answers_list[Type]));
answer1.setText(answers_list[Type][0]);
answer2.setText(answers_list[Type][1]);
answer3.setText(answers_list[Type][2]);
answer4.setText(answers_list[Type][3]);
/*for (int rows = 0; rows < answer&*list.length; rows++){
for (int cols = 0; cols < answers_list[rows].length; cols++){
}
}*/
} catch(Exception ex){
answer1.setText("Error "+ex);
}



}

我想要“答案 1-1”“答案 1-2”“答案 1-3” “答案 1-4”“答案 1-5” 是正确答案,我用它来检查答案是否正确......

switch(view.getId()){
case R.id.button5:
clicks++;
if(clicks > 0)
beginn.setText("Next");
break;
case R.id.button1:
if(answer == 1)
correct++;
else
correct--;
break;
case R.id.button2:
if(answer == 2)
correct++;
else
correct--;
break;
case R.id.button3:
if(answer == 3)
correct++;
else
correct--;
break;
case R.id.button4:
if(answer == 4)
correct++;
else
correct--;
break;

基本上,我需要将我的 answer 整数设置为某个值,我该怎么做?

编辑:我知道它是 answer = number; ,但是什么数字?在我的数组列表被打乱后,如何检查它是否是“Answer 1-1”?不做类似的事情:

 if(answers_list[Type][0] == "Answer 1-1")
answer = 1;
else if(answers_list[Type][1] == "Answer 1-1")
answer = 2;

最佳答案

我不会为此使用二维数组,而是使用一个类来保存问题字符串、错误答案字符串和正确答案字符串。此类可以有一个方法,该方法返回已随机化的潜在答案的字符串数组,并且可以知道哪一个是正确的。

关于java - 打乱数组列表后,如何在数组列表中跟踪正确答案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7699263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com