2017-05-08 1 views
-6

//メインコード私の他にあれば、私のチックのTACのつま先のプログラムでの作業の文イマイチ

のpublic static無効メイン(文字列[] args){

//ゲームボードに開始

initGame(); 
    //start the game 
    do { 
     PlayerMove(Cplayer); 
     updategame(Cplayer, crow, ccol); 
     printboard(); 
     //game over message 
     if (currentstate == you_win){ 
      System.out.println("'X' Won!!"); 
      else if (currentstate == comp_win) 
       System.out.println("'O' won!!"); 
       else if (currentstate == draw) 
       System.out.println("It's a Draw :("); 
     } 
+0

あなたの中括弧は、あなたと噛み合わないように設定されています意図した活動。 ifとelseは同じレベルになければなりません。 – Compass

+2

フォーマットを改善してください。 'do {}'? – Aryan

+2

'currentstate'、' you_win'、 'draw'、' comp_win'のどのデータ型ですか?彼らはストリングじゃない? –

答えて

0
if (currentstate == you_win){ 
     System.out.println("'X' Won!!"); 
     else if (currentstate == comp_win) 
      System.out.println("'O' won!!"); 
      else if (currentstate == draw) 
      System.out.println("It's a Draw :("); 
    } 

この行を見てみましょう(と私は見てこれを容易にするために、いくつかの余分なコードを削除):

if (currentstate == you_win){ 
     else if (currentstate == comp_win) 
      //... 
    } 

このように見ると、なぜこれが間違っているのか分かりますか?ちなみに、このため、常に{}を使用する必要があります。代わりに、このようなif ... else行います。

if (currentstate == you_win){ 
     // ... 
} 
else if (currentstate == comp_win) { 
    // ... 
    } 
    //... 

あるいは、より良いが、ちょうどswitchステートメントを使用します。

switch (currentstate) { 
     case you_win: 
      System.out.println("'X' Won!!"); 
      break; 
     case comp_win: 
      System.out.println("'O' won!!"); 
      break; 

     case draw: 
      System.out.println("It's a Draw :("); 
      break; 
} 
+0

ああ、ありがとう、ありがとう! – fluffytacoo

+0

@fluffytacoo喜んで私は助けることができます - それは問題を解決した場合[あなたは答えとしてこれを受け入れる](http://stackoverflow.com/help/accepted-answer)できますか? – EJoshuaS

関連する問題