This is because the line above your switch
statement has key.nextInt()
*.
The scanner reads the integer, but it leaves the end-of-line character '\n'
in the buffer. You need to consume that '\n'
character somehow, before the key.nextLine();
inside the switch statement returns some relevant data to you.
To fix this problem, insert
key.nextLine();
in front of the switch
statement.
* don't ask me how I know that :-)