0

How to make different inputs of different tipe?

I have tried this code but it does not print the second string https://code.sololearn.com/cI3z10IehGX1/?ref=app

8th Jan 2020, 11:37 AM
Vitaliy Reshetar
Vitaliy Reshetar - avatar
2 RĂ©ponses
+ 1
The reason why is because when you call next line for the first time you get the first line. (as you’d think it would). When you call readInt, it is looking for the next number after that line. (again what you’d expect). But when you do the second readLine, you are actually still reading the same line as the number. If you want to test this yourself just input ‘first line’ in the first line and ‘5 second line’ in the second line of the input. str[1] will return ‘ second line’ Anytime you call nextLine you shift down a line. If you call something other than next line than the scanner is going to stay in the same “place” until you call nextLine again. (Apologizes if this is not 100% accurate, this is just an informed guess I came to based on the code provided).
8th Jan 2020, 11:47 AM
Pie
Pie - avatar
+ 1
Give input like.. First 2 Second The reason is already specified...
8th Jan 2020, 12:58 PM
Jayakrishna 🇼🇳