When you use Scanner with System.in , the data is not read from System.in until a new line (you hit Enter ). So, what do you actually have in the scanner buffer:
Jake\nL\nV\nD\n
The key here is that D not sent to the scanner buffer until you press enter. That's why there \n at the end. Usually, when you call input.next() , the previous stray new line becomes consumed. But when you call input.nextLine() second / third time around the for loop, it reads this jagged ending newline:
here ----v Jake\nL\nV\nD\n
So, you get an empty line, essentially reading everything between D and \n that nothing.
You need to call nextLine() every time and call charAt(0) on the resulting line.
source share