7
In java, when we’re learning to capture data input, usually by text mode, we’re told to use the class Scanner.
Is there any alternative to Scanner to capture data input by text mode? If so, how does it work?
7
In java, when we’re learning to capture data input, usually by text mode, we’re told to use the class Scanner.
Is there any alternative to Scanner to capture data input by text mode? If so, how does it work?
7
As stated in Soen:
BufferedReader and InputStreamReaderBufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
int i = Integer.parseInt(br.readLine());
DataInputStreamDataInputStream dis = new DataInputStream(System.in);
int i = dis.readInt();
The readLine in the DataInputStream is discontinued, to take the value of String you can use the previous solution with BufferedReader.
ConsoleConsole console = System.console();
String s = console.readLine();
int i = Integer.parseInt(console.readLine());
It seems that this method does not work on some Ides.
6
I don’t know if that would be a viable alternative, but you can use JOptionPane to pick up data entry.
String nome = JOptionPane.showInputDialog("Entre com um nome: ");
Browser other questions tagged java data-entry
You are not signed in. Login or sign up in order to post.
Interesting suggestion, but as he said it is by text mode, but leave as an alternative suggestion for those who work
java.swing(it would be interesting to add this detail to the answer). By the way I found a cool example with java.swing: http://answall.com/q/72032/3635 +1– Guilherme Nascimento
@Guilhermenascimento yes, I thought it would not be a 100% viable alternative but I took it because of the title. I will look at this example with swing :D
– DiegoAugusto