BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter your name: ");
String name = reader.readLine();
can i provide input from java code instead of console ?
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter your name: ");
String name = reader.readLine();
can i provide input from java code instead of console ?
You can use a file to do that. Using the same BufferedReader and read the complete input values from the file.
And if not that either, you can't use a simple console project and ask for a graphical input system. You can rather add Java Swing to your project and use a graphically oriented form with text fields for it input.
Use JOptionPane#showInputDialog
to get the input with some graphical dialogs from user instead of console. It is not the ideal way for a professional program but it is so easier for now to get started with swing JFrame
, JTextField
, JComboBox
etc. and diving into the world of handling actions of JButton
or so.
Example:
String input = JOptionPane.showInputDialog(null, "Please enter your name: ");
More detailed JOptionPane#showInputDialog
overloads are available and if you want to create more elegant input dialogs. A quick tutorial can be found here.