Reading The Data From Keyboard
To Read data from the keyboard in java, we can use pre-defined class called "Scanner" and it is present in package called "java.util.*" .
When we use Scanner class its a part of Java Program we must import "Java .Util.*"; Other Wise we get compile time error will occurs in java.
Scanner is one of the new facility present in JDK 1.5 version onward Reading the data form the keyboard is nothing but creating an object of Scanner class.
Profile of java .Util .*:-
1) Constructor
a)Scanner (InputStream)
2) Instance Methods
a)public String nextLine( )
b)public String nextLine( )
➤ Constructor 1 is used for creating an object of Scanner class. By passing an object of "InputStream".
➤ An object of Input Stream called "in" created as a static data member in an another predefined class called System & hence it must be access as " System.in ".
EX:- Create an object of Scanner
Scanner S = new scanner (System.in);
here S is an object of Scanner Class and it use to the read data from the keyboard.
here System.in it provides an environment to read the data form.
Method 1 : Represents any fundamental data type
Method 2 : Used for reading any fundamental data type from keyboard
Method 3 : Used for reading any type of data in the string type.
No comments:
Post a Comment
Thanks for visiting my site..