SCIENCE.
Trusted by students across multiple disciplines!
Scanner class - Answer: It is often useful to design interactive programs that read input
data from the user
The Scanner class provides convenient methods for reading input values of various
types
A scanner object can be set up to read input values from various sources including the
user typing values on the keyboard
How does Scanner get user input? - Answer: You create a Scanner object:
Scanner scan = new Scanner(System.in);
Once created, the Scanner object can be used to invoke various input methods, such
as:
String answer = scan.nextline();
The nextline method reads all of the input until the end of the line is found, and return it
as one String
Scanner methods - Answer: nextint();
Nextdouble();
Nextfloat();
Nextlong();
Nextbyte();
Nextshort();
1
APPHIA - Crafted with Care and Precision for Academic Excellence.