+ 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
6 Answers
+ 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