Java instance--receives the entered ID number from the console

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.