← Back to User Input
Question 39
Buffer Issue with nextInt and nextLine
Buffer Issue with nextInt and nextLine
Write a program that reads an integer, then reads a full name (with spaces). Display: Number: [number] Name: [name] IMPORTANT: After usingnextInt(), you must callnextLine()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. Callscanner.nextInt(), thenscanner.nextLine()to clear buffer, thenscanner.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 — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
User Input
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (sysout, psvm, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.