gpt4 book ai didi

java - 单个 java switch 语句返回 2 个变量

转载 作者:行者123 更新时间:2023-12-01 20:16:48 25 4
gpt4 key购买 nike

我正在尝试设置一个问答对话框,该对话框将提出几个问题并存储同样多的答案。当我通过 QuestionsAnswer.java 传递一个 int 时,它将设置 @string/questions[i]@string/answers[i]。我试图通过搜索这里和java的文档来找到我的答案,但没有成功。

伪代码:

public class QuestionAnswer {

public static void QuestionAnswer(int QuestionNum) {

String question;
String answer;
switch (QuestionNum) {
case 1: question = "What are you doing?", answer = "activity";
break;
case 2: question = "Where have you been?", answer = "Location";
break;
case 3: question = "Are you looking at me?", answer = "Boolean";
break;
case 4: question = "What do you think about when I'm not around?", answer = "Crazy";
break;
case 5: question = "Do you want to play a game?", answer = "MovieQuote";
break;
case 6: question = "Does a cat have nine lives?", answer = "CanCatsFly";
break;
}
//question is a string variable that will change the question text for the dialog
R.string.Questions = question;
//answer is a string variable that will change what column name the answer will be stored into
R.string.answers = answer;
}
}

Here is the finished version after the edit. It works perfectly! public class QuestionAnswer {

    public static void QuestionAnswer(int QuestionNum) {


String question;
String answer;
switch (QuestionNum) {
case 1: question = "What are you doing?";
answer = "activity";
break;
case 2: question = "Where have you been?";
answer = "Location";
break;
case 3: question = "Are you looking at me?";
answer = "Boolean";
break;
case 4: question = "What do you think about when I'm not around?";
answer = "Crazy";
break;
case 5: question = "Do you want to play a game?";
answer = "MovieQuote";
break;
case 6: question = "Does a cat have nine lives?";
answer = "CanCatsFly";
break;
}
//question is a string variable that will change the question text for the dialog
R.string.Questions = question;
//answer is a string variable that will change what column name the answer will be stored into
R.string.answers = answer;
}
}

最佳答案

您可以使用;

switch (QuestionNum) {
case 1: question = "What are you doing?";
answer = "activity";
break;
//continue with next cases
}

关于java - 单个 java switch 语句返回 2 个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45645940/

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