Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to take user inputs in eclipse?

Tags:

java

Hi how to take user inputs using eclipse. Like in command prompt we do

C:/ java javaApp (arguments here). How to make eclipse to take inputs from the user.?

like image 828
pradeep Avatar asked Feb 07 '11 05:02

pradeep


People also ask

How do you take user input in Java?

The best and most simple alternative to taking char input in Java would be the next(). charAt(0). The charAt(0) command is used in combination with the simple next() command which instructs Java to record the next character or string that is input into the command line.

What are the 3 ways to input in Java?

Java provides three classes to take user input: BufferedReader, Scanner, and Console. We can also provide inputs to a Java program through Command Line Arguments to the main() method.


2 Answers

Run --> Run Configurations --> Arguments (it is the 2nd tab on the right) --> Program arguments

like image 181
WuHoUnited Avatar answered Oct 19 '22 04:10

WuHoUnited


Add this line in your program to accept user's input from the console:

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

and then add in.readLine() beside whatever variable you want to accept input from Runtime. Lets say, you want to initialize count variable to the value 1, then, it should be written as

int count = in.readLine(); The value 1 should be inputted in the console after you run the program

like image 2
Surya Chandra Avatar answered Oct 19 '22 03:10

Surya Chandra