A story packed with Java's standard input Scanner

I'm stuck with Java standard input

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 **.

Example

Standard input: ʻa 123 → Acquisition: ʻa

nextInt(); This also reads standard input up to ** blank **. The return value is ** int **.

Example

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 **.

Example 1

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`.

Example 2

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`.

Based on the above

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

A story packed with Java's standard input Scanner
A story stuck with NotSerializableException
A story packed with the basics of Spring Boot (solved)
A little addictive story with def initialize
Reading a file using Java's Scanner class
Create a multi-key map with the standard library
Ruby standard input
[PHP] A story about outputting PDF with TCPDF + FPDI
The story of making a reverse proxy with ProxyServlet
A story about trying to get along with Mockito
A story about reducing memory consumption to 1/100 with find_in_batches
A story about developing ROS called rosjava with java