2017-11-15 4 views
-4

私のコードはエラーがないかのようにコンパイルされますが、実行すべきコードは本当に実行されません。助けてください。パラメータが真であっても私の "if文"は実行されません

public static void newGameCheck() { 
    String newCharacter = scan.next(); 
    if (newCharacter.equals("New game")) { 
    //more code here, but it does not get executed for some reason 
    } 

そして、もう一つの例はここにある:ここで

public static void warriorTurn() { 
    if (warriorAlive==true) { 
     etut.choosingTarget(); 
     int target= scan.nextInt(); 
     System.out.println("Now type in which ability you want him to use, make sure to use capitals"); 
     warrior_Weapons_and_Abilities(); 


String ability= scan.next(); 
      if (ability.equals("Anduril, Foe of Terror")) { 
       int damage= 100+((int) (Math.random()*50)); 
       etut.loseHealth(target, damage); 
       mana2=mana2-0; 
       etut.displayHealth(target);   
      } 
      else if (ability.equals("Aethereal Blades")) { 


int damage= 250+((int) (Math.random()*100)); 
       etut.loseHealth(target, damage); 
       mana2=mana2-2; 
       etut.displayHealth(target);    
      } 
      else if (ability.equals("Potion")) { 
      health2=health2+100; 
      mana=mana-0; 
      etut.displayHealth(target); 




    } 

^私は能力名を入力するたびに、コードがまだscan.nextLine()

+0

質問に関連する言語タグを追加してください。 –

+1

デバッガでコードをステップ実行しましたか? – OldProgrammer

+3

プログラムをデバッグしてください。 – f1sh

答えて

1

変更すべてscan.next()を実行しません。 scan.next()は1語だけを読みます。

0

Scannerのnext()メソッドは、次のトークンを返します。デリミタが改行に設定されていない限り、おそらく最初の単語を返すだけです。

関連する問題