How to make different inputs of different tipe? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 Answers
+ 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 šŸ‡®šŸ‡³