+ 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!
6 Answers
+ 1
Ohk guys. I found a solutions.
System.out.println(myVar.nextLine());
It works. Thank you for spending your precious time.
+ 2
@Ratnesh Mishra at 3:10 of the video he does the same thing as me
+ 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);
+ 1
If youre trying to get input from myVar and print it then replace your println with:
System.out.println(myVar.nextLine());
+ 1
And so you can.But it is good practice to assign the received value at once
+ 1
Yes @TurtleShell. I was wrong. Thank You