Scanner waits for nextInt() until the user presses the enter button. When this happens, it consumes numbers, but not a new line symbol. Thus, the next call to nextLine() immediately returns with an empty String as the result.
This should fix:
int selection = input.nextInt(); input.nextLine(); if (selection == 1) { System.out.println("Please enter a string: "); String code = input.nextLine();
But my preferred way is to always use nextLine and parse separately:
String selectionStr = input.nextLine();
source share