Accepting input from keyboard: –

  • In order to read the input from keyboard, inside system class variable such as ‘in’
  • So we represent keyboard as (System.in)
  • (System.in) is also represented as InputStream object.
  • (System.out) is also represented as PrintStream object.
  • (System.err) is also represented as PrintStream object.
  • To read the value from keyboard, we create an object of InputStreamReader class. And inside the parenthesis of class name we have (System.in)
Ex: - InputStreamReader irr=new InputStreamReader(System.in);
  • To read data property, we use BufferedReader class.
  • BufferedReader class has methods to read the data efficiently. So, the object of InputStreamReader must be passed inside the parenthesis of BufferedReader class.

Ex: –

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                Or
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);

Accepting character from keyboard: –

  1. To read a character in keyboard on monitor we use read() method of BufferedReader class.
  2. Read() method accept the value as ASCII integer byte.
  3. So, the integer value must be type casted explicitly into character type to store if into character type variable.
Advertisements