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