你可以帮我解决android studio中测验随机问题的代码吗?我知道随机的代码,但问题是我也有答案,我不知道如何连接它。这是我的代码:
public class Questions {
public String mQuestions[]= {
"Care este prima planeta?",
"Cine a fost primul presedinte al SUA?",
"In ce an a murit Adolf Hitler?",
"De cate ori a iesit Michael Schumacher campion mondial al F1?",
"La ce echipa a jucat Gica Popescu in Spania?"
};
private String mChoices[][]={
{"Mercur","Venus","Pamant","Marte"},
{"Abraham Lincoln","William H. Taft","George Washington","John F. Kennedy"},
{"1940","1945","1944","1947"},
{"3","2","4","7"},
{"Barcelona","Real Madrid","Valencia","Espanyol"}
};
private String mCorrectAnswers[]={"Mercur","George Washington","1945","7","Barcelona"};
public String getQuestion(int a){
String question = mQuestions[a];
return question;
}
public String getChoice1(int a){
String choice= mChoices [a][0];
return choice;
}
public String getChoice2(int a){
String choice= mChoices [a][1];
return choice;
}
public String getChoice3(int a){
String choice= mChoices [a][2];
return choice;
}
public String getChoice4(int a){
String choice= mChoices [a][3];
return choice;
}
public String getCorrectAnswer(int a){
String answer=mCorrectAnswers[a];
return answer;
}
}
答案 0 :(得分:0)
为什么不使用类或结构这样的问题:
class Question
{
String Question;
String[] Choices;
int CorrectChoiceIndex;
}
这样,所有相关数据都存储在一起,所以如果你创建一个问题数组,你只需选择一个有效的随机索引。