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