0
0

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 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行に複数の文字列を入力できます。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?