Java System in Field
Example
Read a line of text that the user types, with System.in:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in);
System.out.println("Enter your name:");
String name = myObj.nextLine();
System.out.println("Hello " + name);
}
}
Definition and Usage
The System.in field is the standard input stream. It reads the data that the user types on the keyboard.
It reads raw bytes, so it is usually used together with a Scanner object, which can read whole lines, words and numbers.
Tip: Read more about the Scanner class in our Java User Input Tutorial.
Syntax
public static final InputStream in
Related Pages
❮ System Methods