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

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -