Page 129 - CA_Blue( J )_Class9
P. 129
You will get the following output:
6.6 USING INPUTSTREAMREADER CLASS
Using this class, we can input values from the users whenever required at the time of execution. To use this class,
we need another class called BufferedReader class that allows us to read input line by line. We also need to create
the object of this class. To utilise InputStreamReader class, we need to include a package called “java.io”.
import java.io.*;
[Used to include the package]
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
[Used to create the object which contains the methods required to input values]
All input values taken from the user are initially in the form of strings. These values must be converted to the
required data types using appropriate methods.
1. To accept a word or a line:
String w=br.readLine();
2. To accept an Integer:
a. Integer of size 1 byte
byte b= Byte.parseByte(br.readLine());
b. Integer of size 2 bytes
short s= Short.parseShort(br.readLine());
c. Integer of size 4 bytes
int n= Integer.parseInt(br.readLine());
d. Integer of size 8 bytes
long l= Long.parseLong(br.readLine());
3. To accept a real number:
a. Real number of size 4 bytes
float f=Float.parseFloat(br.readLine());
b. Real number of size 8 bytes
double d=Double.parseDouble(br.readLine());
4. To accept a character:
char c= br.readLine().charAt(0);
Input in Java 127

