Sunday , June 13 2021
Home / Java / JAVA #07 – Scanner Class in Java

JAVA #07 – Scanner Class in Java

Scanner class:

The Scanner class is a class in java.util, which allows the user to read values of various types. There are far more methods in class Scanner than you will need in this course. We only cover a small useful subset, ones that allow us to read in numeric values from either the keyboard or file without having to convert them from strings and determine if there are more values to be read.

Numeric and String Methods of String Class

 

Method Returns
int nextInt() Returns the next token as an int. If the next token is not an integer,InputMismatchException is thrown.
long nextLong() Returns the next token as a long. If the next token is not an integer,InputMismatchException is thrown.
float nextFloat() Returns the next token as a float. If the next token is not a float or is out of range, InputMismatchException is thrown.
double nextDouble() Returns the next token as a long. If the next token is not a float or is out of range, InputMismatchException is thrown.
String next() Finds and returns the next complete token from this scanner and returns it as a string; a token is usually ended by whitespace such as a blank or line break. If not token exists,/NoSuchElementException is thrown.
String nextLine() Returns the rest of the current line, excluding any line separator at the end.
void close() Closes the scanner.

About Faheem

An adaptable and responsible Software Engineer, who enjoys working with computers and the opportunity to learn new skills and work with new technologies is particularly attractive to me.

Check Also

JAVA #32 – Java application using SQL server (Part: 01)

  In this part we made the GUI front end of a Application.

Leave a Reply

Your email address will not be published.