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
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).
+ 1
Give input like..
First
2 Second
The reason is already specified...