0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Java Scanner 使い方

Last updated at Posted at 2016-08-30

標準入力を読む時等使える.

Input bufferのキューに入っている入力を順に読んでいく.

以下使用例

この問題に対する回答

.java
import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int i = scan.nextInt();
        double d = scan.nextDouble();
        scan.nextLine(); // nextDoubleでは行の最後まで読まれていない可能性があるためスキップしたい.
        String s = scan.nextLine();

        System.out.println("String: " + s);
        System.out.println("Double: " + d);
        System.out.println("Int: " + i);
    }
}

  • nextInt(): Intを見つけるまでQueueを進めて、そのIntをQueueから出した時点でそのInt値を戻り値として返す.
  • nextDouble(): Doubleバージョン
  • nextLine(): 行の最後にたどり着くまでを、Queueから出して戻り値とする.
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?