0

Why the scanner object not accepting the string input from stdin ?

I've used scanner object for accepting 2 inputs First int input =4 and second string input ="ground fun" I don't want to close the scanner object and then create a new scanner object for string input Expected output should be 8 Playground fun https://code.sololearn.com/c0hlmzoAUjYP/?ref=app

14th Apr 2022, 8:21 AM
Krishna Kumar
Krishna Kumar - avatar
2 Réponses
0
It's something about the buffer. Put this between line 12 and 13: sc.nextLine()
14th Apr 2022, 8:44 AM
Lisa
Lisa - avatar
0
nextInt() doesn't read end_of_line after number, so nextLine() reads end_of_line and not expected second input in input: 4 ground fun
14th Apr 2022, 3:30 PM
zemiak