I have been using the Scanner object to take in input until now and would like to learn how the BufferedReader works. I have tried it and it seems to be working only for Strings. can someone show me how to use it with ints and doubles?and how do you ask for two String inputs on the same line? Thanks.
Think of BufferedReader
and Scanner
as being at different levels of abstraction, rather than interchangeable parts that "do the same thing." I think this is the fundamental issue that you're hung up on.
BufferedReader
is in some sense "simpler" than Scanner
. BufferedReader
just reads String
s.
Scanner
is much more robust than BufferedReader
. It has APIs that make it easy for extracting objects of various types.
I could imagine Scanner
being written using BufferedReader
as an underlying building block. Whereas using Scanner
to write BufferedReader
would be like killing an ant with a sledgehammer.
Yes, bufferedreader will take only Strings. you need to convert them into int or double as required using Integer.parseInt(value) or Double.parseDouble(value)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With