Java example - receive input ID number from console

Technical key:
1. The input stream of the System class (that is, the class variable in) is a standard input stream instance object that can receive user input information. In addition, the Scanner class is a Java scanner class, which can read data or strings of a specified type from an input stream.
2. This example uses the Scanner class to encapsulate the input stream object, and uses the nextLine() method to obtain the entire text string input by the user from the input stream.
 
Implementation process:
1  package test;
 2  import java.util.Scanner;
 3  
4  public  class InputCode {
 5      public  static  void main(String[] args) {
 6          // TODO Auto-generated method stub 
7          Scanner scanner = new Scanner(System.in) ;     // Create an input stream scanner 
8          System.out.println("Please enter your ID number:");      // Prompt the user to input 
9          String line = scanner.nextLine();             // Get a line of text input by the user
 10          // Print a description of the input text 
11         System.out.println("Your ID number is" + line.length() + "digits" );
 12      }
 13 }

The running result is shown in the figure:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325029634&siteId=291194637