sc.nextInt() leaves a linefeed in the input buffer which is then taken as input for the next sc.nextLine() call. Flush the buffer and throw it away with a sc.nextLine() call after the nested for...