Java OCA OCP Practice Question 2646

Question

Which one of the following options correctly reads a line of string from the console?

a) BufferedReader br = new BufferedReader(System.in);
   String str = br.readLine();//from   www  .j a v  a 2s . co m

b) BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String str = br.readLine();

c) InputStreamReader isr = new InputStreamReader (new BufferedReader(System.in));
   String str = isr.readLine();

d) String str = System.in.readLine();

e) String str;
   System.in.scanf(str);


b)

Note

This is the right way to read a line of a string from the console where you pass a System.in reference to InputStreamReader and pass the returning reference to BufferedReader.

From the BufferedReader reference, you can call the readLine() method to read the string from the console.




PreviousNext

Related