Technical key: 1, the System class input stream (that is, class variable in), is the standard input stream instance object, can receive the user's input information. In addition, the scanner class is the scanner class for Java, which can read data or strings of the specified type from the input stream. 2. This example uses the scanner class to encapsulate the input stream object, and uses the Nextline () method to get the entire line of text string from the input stream for the user input. Implementation process:
1 Packagetest;2 ImportJava.util.Scanner;3 4 Public classInputcode {5 Public Static voidMain (string[] args) {6 //TODO auto-generated Method Stub7Scanner Scanner =NewScanner (system.in);//Create an input stream scanner8System.out.println ("Please enter your ID number:");//Prompt for user input9String line = Scanner.nextline ();//gets the line of text entered by the userTen //Print a description of the input text OneSYSTEM.OUT.PRINTLN ("Your ID number is" + line.length () + "digits"); A } -}
Operation Result:
Java instance--receives the entered ID number from the console