0

Why is this line being skipped?

This isn’t running right in SoloLearn, but when I run this on my PC, everything executes except for the line answer = input.nextLine(); It ends on “Is that correct?” and doesn’t give me the option to input anything for answer. I’ve tried a couple different ways and can’t pin this one. Thank you! https://code.sololearn.com/cDrDFXsID8oE/?ref=app

12th Nov 2018, 3:05 PM
p.xela
p.xela - avatar
4 Respuestas
+ 7
On SL playground, the compiler does a little different than on your IDE on pc. You need to enter all the required values ​​at the beginning (separated by a space or new line) and start the code.
12th Nov 2018, 5:50 PM
Danijel Ivanović
Danijel Ivanović - avatar
12th Nov 2018, 11:06 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 5
It does read, but nextInt doesn't read the new line after the age so nextLine reads that one and not your answer. Any time you read with any next method other than nextLine you are left with the new line ending that line so should always follow it a nextLine call. However, a second nextInt will skip whitespace so will skip over the new line.
12th Nov 2018, 10:47 PM
John Wells
John Wells - avatar
+ 1
Danijel Ivanović why on my PC does it not run the line before last that asks for answer input?
12th Nov 2018, 5:52 PM
p.xela
p.xela - avatar