+ 1
Why scanner object dont read last line of input
For input value of "World" in cc and "Hello" for c, System.out.println(c + cc); only prints Hello https://code.sololearn.com/c4pz871dBB5F/?ref=app
5 Antworten
+ 6
Shreyansh
Do like this then it will read.
String cc = null;
if(scan.nextLine() != null)
cc = scan.nextLine();
Or you can just use next() method like
String cc = scan.next();
+ 2
Pąľľąvī
Yes there is another method next ().
Shreyansh
There is a problem with nextLine () method. After using nextInt() or nextDouble(), nextLine method starts reading from the cursor's current position so after reading the value using nextInt or nextDouble, cursor just start reading after the int or double value which will be new line '\n'. That's why cc is just '\n' so you have check like I told you.
+ 1
Thank you I Am AJ !, It really helped a lot 😊
0
Pąľľąvī
There is no nextWord in Scanner class.
0
Yes exactly Pąľľąvī , But when it comes to read a line, problem begins