I thought, for every input, I have to type ''BufferedReader xyz = new BufferedReader..., so typed it two times. Then I compared it with the codegym solution, it created only one.
I wonder what was happening when I created Two BufferedReader objects
Query about inputs
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Michaela Obertova
11 October 2022, 07:58useful
A reader will be capable of reading input as long as it is not closed, so you don't need to create multiple reader instances if you want to read multiple inputs.
As for creating two readers, you were creating unnecessary extra code which is going against the DRY (Do not repeat yourself) principle. There might be further implications of unnecessarily using multiple readers, but explaining those requires more knowledge about I/O than I have at this point, haha.
+1
Amber Singh Rathour Pandey
17 October 2022, 13:33
It was my first instinct, as in C++, you do it like that,
(cin << "variable 1" << endl;
cin << " variable2" << endl;
...)
& in Java, I do similar thing with one extra line.
(BufferedReader reader = ...;
int a1 = Integer.parseInt(reader.readLine());
int a2 = '' '' '' ''
...)
By the way, Java is verbose!
& I don't like it, LOL.
Thanks for your time.
Have a good day!
0
Thomas
17 October 2022, 15:50
In C++ it is similar. cin is an object that you use to read from the console. The BufferedReader object is used for the same purpose.
That means, just like in C++, you use one object to read multiple inputs.
+1