The data type of the any input through console (as i do using BufferedReader class) is String.After that we type cast it to requered data type(as Inter.parseInt() for integer).B
Console input is actually read in as a series of bytes, not a String. This is because System.in
is exposed by the API as an InputStream
. The typical wrapping before JDK1.5 (hooray for the Scanner
class!) was something like:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
i.e. InputStreamReader
converts the byte stream into a character stream and then the BufferedReader
is used to do your readLine()
operations, or whatever.
So it's a String
output because you're getting the buffered output of a character stream from your BufferedReader
.
In java you can do:
Scanner scan = new Scanner(System.in);
scan.nextInt();
scan.nextDouble();
etc. You just need to make sure the next input is correct.
EDIT: Missed the Buffered Reader part. I think this answer is totally irrevelant.