How to use Java Scanner class (Note)

How to use the Scanner class (memorial)

Overview

I used the Scanner class for the first time to solve the problems on the learning site, so I will summarize it as a memorandum.

This time, only the standard input method used in the assignment and the method of acquiring an integer are available. We plan to learn more about the Scanner class in the future.

Scanner class

スクリーンショット 2017-03-11 11.33.49.png

Import of Scanner class

First, you need to import the Scanner class.

The Scanner class is included in the java.util package, so if you write "import java.util. *;", All the classes in the java.util package will be imported.

Of course, "import java.util.Scanner;" is also OK.

Pass standard input information

Then pass the standard input information to an instance of the Scanner class.

Standard input can be obtained from the in field of the System class.

Get input information

Here is the acquisition method when line breaks and spaces are delimiters.

To get an integer, write "nextInt".

In the case of a character string, the description method will change according to the data type to be acquired, such as writing "next".

スクリーンショット_2017-03-11_11_33_49.png

That's all for this time.

reference

I referred to the following article. http://www.javadrive.jp/start/scanner/index2.html http://eng-entrance.com/java-scanner-type http://todai-neet.hateblo.jp/entry/2015/09/01/131413

Recommended Posts

How to use Java Scanner class (Note)
How to use java class
[Java] How to use LinkedHashMap class
How to use class methods [Java]
[Java] How to use Math class
[Java] How to use the File class
[Java] How to use the HashMap class
[Processing × Java] How to use the class
[Java] How to use the Calendar class
[Java] How to use FileReader class and BufferedReader class
[Java] How to use Map
How to use java Optional
[Java] How to use string.format
How to use Java Map
How to use Java variables
[Java] How to use Optional ①
[Java] How to use Calendar class and Date class
[Java] How to use compareTo method of Date class
[Rails] How to use devise (Note)
How to disassemble Java class files
How to use Java HttpClient (Post)
[Java] How to use join method
[Processing × Java] How to use variables
How to decompile java class files
[JavaFX] [Java8] How to use GridPane
[Java] How to use List [ArrayList]
How to use classes in Java?
[Processing × Java] How to use arrays
How to use Java lambda expressions
How to use Java enum type
java Scanner class
A story about misunderstanding how to use java scanner (memo)
Multilingual Locale in Java How to use Locale
[Java] How to use the hasNext function
How to use submit method (Java Silver)
[Java] How to use the toString () method
Studying how to use the constructor (java)
[Processing × Java] How to use the loop
How to use Java classes, definitions, import
[Easy-to-understand explanation! ] How to use Java polymorphism
[Java] [Maven3] Summary of how to use Maven3
[Note] How to use Rails 6 Devise + cancancan
[Processing × Java] How to use the function
[Easy-to-understand explanation! ] How to use ArrayList [Java]
Ruby: CSV :: How to use Table Note
[Java] Learn how to use Optional correctly
[Easy-to-understand explanation! ] How to use Java overload
try-catch-finally exception handling How to use java
[Easy-to-understand explanation! ] How to use Java encapsulation
How to use Map
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to use Twitter4J
How to use active_hash! !!
How to use MapStruct
How to use TreeSet
[How to use label]
How to use hashes