Buffer Issue with nextInt and nextLine
mediumQuestion 39Write a program that reads an integer, then reads a full name (with spaces). Display:
Number: [number] Name: [name]
IMPORTANT: After using nextInt(), you must call nextLine() once to clear the leftover newline before reading the actual name.
Example: If user enters 25 and then "Jane Smith", output should be exactly what is shown in Expected Output.
⚠️ IMPORTANT - AUTO-INPUT MODE: This question uses automated input testing. When you run your code, the input stream will AUTOMATICALLY contain: '25\nJane Smith\n'
DO NOT wait for manual keyboard input - Scanner will read from the pre-filled buffer stream immediately. Call scanner.nextInt(), then scanner.nextLine() to clear buffer, then scanner.nextLine() again for the name.
Think of it like Eclipse/VS Code but with the input already typed in and waiting for your Scanner to read it.
Expected output
Number: 25 Name: Jane Smith
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...