2017-08-12 8 views
0

私はいくつかの質問をし、多くの答えを保存する質問と回答のダイアログを設定しようとしています。 QuestionsAnswer.javaにintを渡すと、@string/questions[i]@string/answers[i]が設定されます。私はここで検索することで自分の答えを見つけようとしました。単一のjava switch文が2つの変数を返す

擬似コード:

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

ここでは、編集後の完成版です。それは完全に動作します! パブリッククラス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; 
    } 
} 
+1

を使用することができます... –

+0

それをすべて投げ捨て、ある種のテーブルを使用してください。 – EJP

+0

私は構文エラーを嫌いです。笑...しかし、今は素晴らしいです!ありがとう! –

答えて

3

あなただけsmicolonとコンマ( ``)( `;`)置き換える、あなたの擬似コードは動作するはずです;

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

助けてくれてありがとう!私はすべてのJavaで約3週間持っている。 –

+0

@MichaelVioxようこそ。私は、Javaの基本的な構文に慣れてから、OOPSを読むことをお勧めします。解決しようとしている問題には、より多くのより良い実装方法があります。 –

関連する問題