instead of scanner.nextLine(), you could use scanner.next() .... This will get a string from the scanner when it does not have an end of line character.
You can also call scanner.hasNextLine() to check if you have reached the line at the end that you are worried about!