What is system.in

前端 未结 9 1096
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 05:50

Consider this Scanner input example.

Scanner user_input = new Scanner( System.in );

Here Scanner is the CLASS.

9条回答
  •  遥遥无期
    2021-02-06 06:39

    System.in - "in" is object of class InputStream which is defined as static variables in class "System" which is used to read data from the console. In short "System.in" gives you a instance of of type InputStream.

    When we create a Scanner class object we need to pass "System.in" as parameter in Scanner class Constructor. So basically using "System.in" Scanner class becomes able to read the data from console and then using different methods which are provided by Scanner class (like nextInt(), nextLong(), next() etc.), we can get data in the form of our desired datatypes (like int, double, String etc.).

提交回复
热议问题