As the title suggests, I got stuck when getting Java standard input. Scanner differences
The Scanner method that appears this time is
next(); It reads standard input up to ** blank **.
Standard input: ʻa 123 → Acquisition: ʻa
nextInt(); This also reads standard input up to ** blank **. The return value is ** int **.
Standard input: 1 abc
→ Acquisition: 1
nextLine(); This is different from the above two points, and there are two points to note. -** Read up to line feed (\ n) ** --Read blanks The return value is ** String **.
Standard input
1
aa
Get
1
If this is written in one line, it is 1 \ naa
, so read up to 1
before \ n
and the read start position is before ʻaa`.
Standard input
1 abc
aa
Get
1 abc
If this is written in one line, it is 1 abc \ naa
, so read up to 1 abc
before \ n
and the read start position is before ʻaa`.
Standard input
a
2 3
b
4
c
If you want to take all the numbers / letters as
1. next(); or nextLine(); →a
2. nextInt(); →2
3. nextInt(); →3
4. next(); →b
5. nextInt(); →4
6. next(); or nextLine();→c
Will be.
Recommended Posts