Java Learning: Scanner class

Source: Internet
Author: User

Scanner:help us get data from the keyboard.
Construction Method:
Scanner (inputstream source)

Scanner sc = new Scanner (system.in);

System.inin is a static member variable under the System class.
now we don't know the data type of this member variable.
take a look at the pseudo-code:
Scanner {
Public Scanner (InputStream in) {}
}

System {
Public static Final inputstream in;
}
InputStream system.in

member Methods:
int Nextint (): Get data of type int
string nextline (): Gets the data of type string

When for the same scanner object, the input order of the data is problematic:
string,string
String,int
Int,int
Int,string

Problems that arise:
The problem occurs with int and string.
Solve:
A: I'll take all the data according to string.
String S1
String S2
String S3
If you want anything in the future, I'll convert the string data into why. (It can be achieved tomorrow)
B: Re-create a new object.

Java Learning: Scanner class

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.