java - player naming with loops -


im having problem loop im doing. when ever run program displays

please enter name of player 1?

please enter name of player 2?

when enter first name automatically prints please enter name of player three. 3 players have been created can name 2 appears advice

   public static void startgame()     {     system.out.println("how many players like?");     int noplayers = input.nextint();     (int = 0; < noplayers; i++)     {          system.out.println("what 1st name of player " + (i + 1) + "?" );           string name = input.nextline();         player player = new player (name, 80);         players.add(player);      } 

note 80 money.

you should add input.nextline() after int noplayers = input.nextint();, consume end of line in number of players entered.

   public static void startgame()    {        system.out.println("how many players like?");        int noplayers = input.nextint();        input.nextline(); // add        (int = 0; < noplayers; i++)        {            system.out.println("what 1st name of player " + (i + 1) + "?" );              string name = input.nextline();            player player = new player (name, 80);            players.add(player);          }    } 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -