Java-scanner input

Source: Internet
Author: User

Java read data-call Scanner class

The first step is to call the scanner class:

Scanner reader=new Scanner (system.in);

Second step, enter:
int A=reader.nextint (); Input integer number (cannot enter a space)
Double b=reader.nextdouble ();//Input doubles (cannot enter a space)
String S1=reader.next (); Input string type (cannot enter a space)
String line=reader.nextline ();//Enter an entire line, in the middle can have spaces and other whitespace characters
Char C=reader.next (). charAt (0); Enter a character type (you cannot enter a space)

Note:

If there is more than one set of data, an indeterminate number can be used
while (Reader.hasnextdouble ()) {

}
Other as while (Reader.hasnextint ()) {

}
while (Reader.hasnext ()) {

}
while (Reader.hasnextline ()) {
}

Java-scanner input

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.