Thursday, 12 March 2015

Scanner Class (Core JAVA)

Scanner Class
·         Scanner src = new Scanner();                     - WRONG
·         Scanner src = new Scanner(System. in);                - RIGHT
int id= src.nextInt();
String UN =src.next();
Double salary = src.nextDouble();
·         Scanner class is used to read the input from the keyboard and this class is available in “java.util” package, hence we have to import this class from this package
·         Scanner class doesn’t have default constructor. It contains overloaded constructor. While creating an instance of Scanner class, we have to call a constructor which takes the input stream type as an argument
·         Inside the scanner class several non-static methods are available to read input from the keyboard. For example, next() method is used to read String data from the keyboard and this method returns String type value

·         nextInt():  It is used to read integer from keyboard and this method returns integer type and etc.

No comments:

Post a Comment