-2

Instead of printing out each statement and waiting for input it prints out both statements and waits for one input.

for(int i=0; i < size; i++)
{
    System.out.println("course: ");
    courses[i] = sc.nextLine();

    System.out.println("teacher: ");
    teachers[i] = sc.nextLine();
}

Output:

Enter number of classes: 2 course:

teacher:

m1o2
  • 1,549
  • 2
  • 17
  • 27
Th3OnlyOn3
  • 3
  • 1
  • 2
  • possible duplicate of [Scanner issue when using nextLine after nextXXX](http://stackoverflow.com/questions/7056749/scanner-issue-when-using-nextline-after-nextxxx) – Piotr Praszmo Jun 28 '14 at 20:21

1 Answers1

1

The new line has been consumed be courses[i] = sc.nextLine(); so that is why it skipped

solution:

add nextLine before the forLoop:

sc.nextLine(); //will consume the new line
for(int i=0; i < size; i++){
Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63