0

I know that probably such questions have been asked however, I wasn't able to find a solution. Here I have piece of code that is supposed to simply input names for a school class, but when I execute it for some reason it prints out 2 at a time. This happens only when I use nextLine.

  do {
        System.out.println("Input a number for the size of your class -> ");
        n = sc.nextInt();
    } while (n < 5 || n > 35);

    for (int i = 0; i < n; i++) {

        System.out.println("Input both names for each classmate at " + i + " position -> ");
        names[i] = sc.nextLine();
    }
}
Help
  • 11
  • 1

0 Answers0