I am making a game and currently I need to set the names for the 'heroes'! This requires the player to enter a name for the heroes. The thing is, when it asks for the name of hero 1 in the console, it just skips over and goes straight to hero 2. If I use .next() instead of .nextLine(), it works, but it interpreted any names with a space in them as two different names!
Here is the code, I hope that make sense! Thanks all in advance :)
public void heroNames() //sets the name of heroes
{
int count = 1;
while (count <= numHeroes)
{
System.out.println("Enter a name for hero number " + count);
String name = scanner.nextLine();
if(heroNames.contains(name)) //bug needs to be fixed here - does not wait for user input for first hero name
{
System.out.println("You already have a hero with this name. Please choose another name!");
}
else
{
heroNames.add(name);
count++; //increases count by 1 to move to next hero
}
}
}