I am practicing my coding skills on code chef and a line of code in java has perplexed me. Can someone explain it in a simple way.
InputStream inputStream = System.in;
This syntax of input stream, can someone explain it to me?
CodePudding user response:
in a clearer way for now you must know that inputStream is a class where one of its usefull functions to get input of data from user maybe or any other place so for that you create an instance of this class
InputStream inputStream
and then you initiate this input by "where i should get the input of data?" so
= System.in;
means i want to get input from system (example : keyboard)
CodePudding user response:
Consider you are reading keyboard input(Standard input stream), then usually you do:
Scanner scanner=new Scanner(System.in);
Here, Scanner constructor is accepting java.io.InputStream
parameter which System.in
is returning.
in
is public static member variable of System
class of type java.io.InputStream
.