1
0

More than 3 years have passed since last update.

Javaで1行に複数個の文字列を入力する方法

Posted at

競技プログラムで1行に複数個の文字列を標準入力する方法です。

package nogizaka;
// Scannerクラスをインポートする
import java.util.Scanner;

public class paiza1 {
    public static void main(String[] args) {
        //Scannerクラスを呼び出す
        Scanner scanner = new Scanner(System.in);
        //文字列の個数が全て入力するまで繰り返す
        while (scanner.hasNext()) {
            //文字列を1個ずつ標準出力する
            System.out.println(scanner.next());
        }
        //Scannerクラスを閉じる
        scanner.close();
    }
}

上記のようにコードを書くと1行に複数の文字列を入力できます。

1
0
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
1
0