0

I am working on writing a for loop that will keep track of players on a team. First, the loop asks how many players, then you add in the info.

The first iteration is completely skipping the player name and I can't figure out why when the remaining iterations collect the player name correctly.

Code:

System.out.print("Enter the number of players on your team: ");
    int n = s.nextInt();

    for(int i = 1; i <= n; i++) {
        System.out.println("Player's name: ");
        name = s.nextLine();
        System.out.println("Player's position: ");
        position = s.nextLine();
        System.out.println("Player's jersey number: ");
        number = s.nextLine();
    }

Result:

Results of for loop

StaceyM
  • 35
  • 6
  • See https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo – user May 30 '20 at 22:56

0 Answers0