Scanner| Method name | Description |
|---|---|
nextInt()
|
reads and returns the next token as an int, if possible
|
nextDouble()
|
reads and returns the next token as double, if possible
|
next()
|
reads and returns a single word as a String
|
nextLine()
|
reads and returns an entire line as a String
|
Example:
import java.util.*; // so you can use Scanner
...
Scanner console = new Scanner(System.in);
System.out.print("How old are you? "); // prompt
int age = console.nextInt();
System.out.println("You typed " + age);