Error in Eclipse. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Error in Eclipse.

I wrote a very simple program in Java on Eclipse and got an error. Code was - import java.util.Scanner; public class Input { public static void main(String[] args) { Scanner myVar = new Scanner(System.in); System.out.println(myVar); } } And the result - java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\Q?\E][infinity string=\Q?\E] Link to the code - https://code.sololearn.com/c2kA79UUB205 Please help!

25th Mar 2018, 10:24 AM
Ratnesh Mishra
Ratnesh Mishra - avatar
6 Answers
+ 1
Ohk guys. I found a solutions. System.out.println(myVar.nextLine()); It works. Thank you for spending your precious time.
25th Mar 2018, 11:37 AM
Ratnesh Mishra
Ratnesh Mishra - avatar
+ 2
@Ratnesh Mishra at 3:10 of the video he does the same thing as me
25th Mar 2018, 11:35 AM
TurtleShell
TurtleShell - avatar
+ 1
You can not immediately display the value obtained through Scanner. First you need to assign the value to a variable. Scanner myVar = new Scanner(System.in); int a = myVar.nextInt(); System.out.println(a);
25th Mar 2018, 11:06 AM
Aidos Zhakupov
Aidos Zhakupov - avatar
+ 1
If youre trying to get input from myVar and print it then replace your println with: System.out.println(myVar.nextLine());
25th Mar 2018, 11:06 AM
TurtleShell
TurtleShell - avatar
+ 1
And so you can.But it is good practice to assign the received value at once
25th Mar 2018, 11:36 AM
Aidos Zhakupov
Aidos Zhakupov - avatar
+ 1
Yes @TurtleShell. I was wrong. Thank You
30th Mar 2018, 3:21 AM
Ratnesh Mishra
Ratnesh Mishra - avatar