Maybe you should change your loop to use 'sc.next ()'
for ( int x = 0; x < lines; x++ ) { System.out.print("String #" + x + ": "); text[x] = sc.next(); }
This can be explained using the Java API.
String next (): finds and returns the next full token from this scanner.
String nextLine (): advances this scanner beyond the current line and returns a missed input.
source share