The Scanner class is a class that's able to parse data types when you input a value.
For example, I'm going to make a class that prints back what you've inputted.
In order to use the Scanner class, you're going to have to import the package like so:
import java.util.*;
Create our class:
public class Test {
Add our main method:
public static void main(String[] args) {
Now we'll have to create an object in order to use the class:
Scanner scan = new Scanner(System.in);
Declare a String:
String testing = "";
Print a line:
System.out.println("Type a word: ");
Make it so 'testing' is scanned:
testing = scan.next();
Print back the inputted word:
System.out.println("You entered: "+testing);
The full source code:
import java.util.*;
public class Testing {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String testing = "";
System.out.println("Type a word: ");
testing = scan.next();
System.out.println("You've entered: "+testing);
}
}
I recommend using a InputStreamReader or a BufferedReader rather than this, though.