5 Building Java Programs
5 Building Java Programs
KEYBOARD
1. Scanners
2. BufferedReader
3. JOption Pane
Using Scanners
Interactive programs
• We have written programs that print console output, but it is also
possible to read input from the console.
• The user types input into the console. We capture the input and use it in our
program.
• Such a program is called an interactive program.
• System.in
• not intended to be used directly
• We use a second object, from a class Scanner, to help us.
• Syntax:
// put this at the very top of your program
import packageName.*;
• To use Scanner, you must place the above line at the top of your program (before
the public class header).
Scanner methods
Method Description
nextInt() reads a token of user input as an int
nextDouble() reads a token of user input as a double
next() reads a token of user input as a String
nextLine() reads a line of user input as a String