-4

Ok, so my code will compile as if there are no errors, but then the code that should be executed will not truly run. Please help.

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
    }

And another example is here:

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




    }

Here^, whenever I type in the ability name, the code still will not execute

2 Answers2

1

Change all scan.next() to scan.nextLine(). scan.next() only will read one word.

Leo Aso
  • 11,898
  • 3
  • 25
  • 46
0

The next() method on Scanner returns the next token. It's probably just returning the first word, unless you have the delimiter set to newline.

Tom
  • 46
  • 5