Module 3: Gathering User Input Flashcards

1
Q

Scanner class

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does scanner get user input?

A

You create a scanner object:
Scanner scan = new Scanner(System.in); Once created, the scanner object can be used to invoke various input method, 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Scanner methods

A

nextInt();
nextDouble();
nextFloat();
nextLong();
nextByte();
nextShort();
next();
nextLine();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Do you need to import Scanner?

A

Yes, it is a Class located in the Java.util package so must be imported to be used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly