+ 1

Scanner input function not working

This code is not working in Eclipse ide import java.util.Scanner; class MyClass { public static void main(String[ ] args) { Scanner myVar = new Scanner(System.in); System.out.println(myVar.nextLine()); } }

10th Nov 2016, 4:43 PM
Vivek Thomas
Vivek Thomas - avatar
9 Answers
+ 4
The problem is program is not asking any input? what does leaking resources mean? Please i am a new guy into programming.
10th Nov 2016, 5:30 PM
Vivek Thomas
Vivek Thomas - avatar
+ 1
! appears in the ide, and if i move mouse over it, it says myVar is never closed. I clicked the Scanner.class error and it says the JAR file has no source attachment.
10th Nov 2016, 5:08 PM
Vivek Thomas
Vivek Thomas - avatar
0
What do you mean by not working? Please post the error. EDIT I think it is actually a simple warning, not an error. So you should still be able to run the code. The IDE is just telling you that you have an open stream (you read data from the Keyboard) that you never close. Eventually it will still be closed by the operating system, but in the meantime you are leaking resources. EDIT (2) Leaking resources means wasting (no longer used) resources. This is a typical occurrence when you need to transfer data via a stream or a socket (input/output with files, Internet connections, whatever). First you open your data channel, then when you are done using it you should close it. Just like you would close a water faucet after using it.
10th Nov 2016, 5:02 PM
Giulio Pellitta
Giulio Pellitta - avatar
0
to close it write myVar.close(); if you want that it open a console for running. It will not open. Did you even enter anything? Sorry for being a little rude.
10th Nov 2016, 5:25 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
0
Please watch some youtube video on topic my first java program in Eclipse. It will show you what was wrong. If it does not work try to reinstall Eclipse. Maybe there is a problem in installation.
10th Nov 2016, 5:33 PM
Aditya kumar pandey
Aditya kumar pandey - avatar
0
My problem is it is not prompting any user input box!!
13th Nov 2016, 5:00 AM
Vivek Thomas
Vivek Thomas - avatar
0
The problem resolved... :D
14th Nov 2016, 2:04 AM
Vivek Thomas
Vivek Thomas - avatar
0
if you want the user to input then the code shold look like this import java.util.Scanner; public class MyClass{ public static void main(String[] arg){ Scanner myVar = new Scanner(System.in); String st = myVar.nextLine(); } }
4th Dec 2016, 3:41 PM
Keith Sandamele
Keith Sandamele - avatar
0
hey, what you simply do is type the input in the console area.i.e type whatever input.. if you're using the nextLine(type a word) and press enter,the input appears green when typed, then Press enter. the system outputs whatever word you typed. hope this clarifies you.
4th Jan 2017, 6:48 AM
Aniegbe Joel Ifenna
Aniegbe Joel Ifenna - avatar