Michael Viox
Michael Viox

Reputation: 55

Single java switch statement returns 2 variables

I am trying to setup a question and answer dialog that will ask several questions and store just as many answers. As I pass an int through QuestionsAnswer.java, it will set @string/questions[i] and @string/answers[i]. I have tried to find my answer through searching here and java's docs with no luck.

Pseudo code:

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;
    }
}

Upvotes: 0

Views: 93

Answers (1)

Sagar D
Sagar D

Reputation: 2618

You can use ;

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

Upvotes: 3

Related Questions