learn java - Scanner class

The java.util.Scanner class is one way to read data enter by the user, using an appropriate input device such as keyboard.
The Java Scanner class breaks the input into tokens using a delimiter that is whitespace bydefault. It provides many methods to read and parse various primitive values. 


Commonly used methods of Scanner class

There is a list of commonly used Scanner class methods:

MethodDescription
public String next()it returns the next token from the scanner.
public String nextLine()it moves the scanner position to the next line and returns the value as a string.
public byte nextByte()it scans the next token as a byte.
public short nextShort()it scans the next token as a short value.
public int nextInt()it scans the next token as an int value.
public long nextLong()it scans the next token as a long value.
public float nextFloat()it scans the next token as a float value.
public double nextDouble()it scans the next token as a double value.


Screen shot

Declare the object Input with the datatype Scanner


Using nextLine() method:



Using next() method:





Source code

Comments

Popular posts from this blog

C# Windows Form : PetCare

Fake Call Android Application

Car Wash System vb.net