I am creating some code for a project where I am creating players and countries. It's a country randomizer for a game. I am using while loops to create any number of players and same number of countries.
import java.util.Scanner;
import java.lang.System.*;
public class countryRand
{
public static void main(String[] args)
{
Scanner userInput = new Scanner(System.in); //creates scanner object
out.println("How many players? "); //asks for input for number of players
int limit = userInput.nextInt();
ArrayList<String> players = new ArrayList<String>(); //assigns player names to an array
for (int index = 0; index < limit; index++)
{
out.println("Player" + (index + 1) + " : ");
players.add(userInput.nextLine()); //this is the problem
//I tried this code with the number two for number of players. this for loop prints Player1:
//and player2: but only takes one input for some reason
}
ArrayList<String> countries = new ArrayList<String>(); //assigns country names to an array
for (int index = 0; index < limit; index++)
{
out.println("Country" + (index + 1) + " : ");
countries.add(userInput.nextLine()); //here, however, it works fine
}
}
}