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

单个java switch语句返回2个变量,java,switch-statement,Java,Switch Statement,我正在尝试设置一个问答对话框,该对话框将询问几个问题并存储同样多的答案。当我通过QuestionsAnswer.java传递一个int时,它将设置@string/questions[I]和@string/answers[I]。我试图通过搜索这里和java的文档来找到我的答案,但运气不好 伪代码: public class QuestionAnswer { public static void QuestionAnswer(int QuestionNum) { Stri

我正在尝试设置一个问答对话框,该对话框将询问几个问题并存储同样多的答案。当我通过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;
    }
}
这是编辑后的最终版本。它工作得很好! 公开课问答{

你可以使用

你可以使用


你的伪代码应该可以工作,只要用一个冒号替换逗号;…扔掉它并使用某种表格。我讨厌语法错误lol…但它现在工作得很好!谢谢!你的伪代码应该可以工作,只要用一个冒号替换逗号;…扔掉它并使用某种表格。我讨厌语法错误lol…但它工作得很好现在!谢谢!谢谢你的帮助!我有大约3周的java学习时间。@MichaelViox Welcome。我建议你先学习java的基本语法,然后再阅读OOPS。你试图解决的问题有很多更好的实现方法。谢谢你的帮助!我有大约3周的java学习时间。@MichaelViox Welcome。我建议你尽快解决用Java的基本语法,然后阅读OOPS。您试图解决的问题有很多更好的实现方法。
    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
 }