Sunday, April 1, 2012

Getting User Keyboard Input in Java

This is a sample java program, to get user input from the keyboard to our java program.


import java.io.*;
public class JavaApplication25 {
   public static void main(String[] args)throws IOException {
   InputStreamReader isr=new InputStreamReader(System.in);
   BufferedReader br=new BufferedReader(isr);
   String str=br.readLine();
   System.out.println(str);
   }
}



Copy the above code,and paste it in your Java IDE, Compile it,Run it. The console asks for input,type it,press Enter key,and the console again displays the string that you just input. 

Reference: