← 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 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: Number: 25 Name: Jane Smith ⚠️ 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
Topics:
User Input
Code Editor
1
Tab to indent · Ctrl+Enter to run · 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.