This video tutorial will teach you how to use the Scanner class to read from System.in.
The following code may have been modified to meet Youtube's guidelines. Please go to • Java I/O 00. Input/Output Basics Setup to download the actual file
/**
The Scanner class:
You can use the Scanner in two ways:
1) to read from System.in
2) to read from a file
We will look at how to read from System.in here
**/
import java.util.Scanner;
import java.io.File;
public class ScannerClassSystemIn {
public static void main(String[] args) throws Exception {
// To read from standard in,
Scanner in = new Scanner(System.in);
String input = in.nextLine();
while (!input.equals("-")) {
System.out.println("You typed: " + input);
input = in.nextLine();
}
in.close();
}
}