Java Basic Problems

Java: How to take Run time input from user

Suppose you are doing your coding in java (let you are running your program from command prompt of your desktop) and you need to take input from user in command line or command prompt while  user  run (actually runtime input) your program.

Now I will show you how to take user input from command prompt or command line in java.

Here I have used BufferedReader  and readLine()  to take input from user in command line/ command prompt while the program was running or  simply in run time.

In the example below  br.readLine() takes  input as String, in the next line we have parsed or convert that String into integer.



public class CmdLineInput




String inputa;

int num_std;

BufferedReader br=new BufferedReader(new InputStreamReader(;


System.out.println(“Enter the number of Students:”);



System.out.println(“Number of Students:”+num_std);


 catch(Exception e){}


public static void main(String args[])


CmdLineInput takeinput=new CmdLineInput();




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s