// 入力例:System.in = {A B C}
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();
String[] params = line.split(" "); // 配列にしてしまう
System.out.println(params[0]); // A
System.out.println(params[1]); // B
// 蛇足
System.out.println(params); // オブジェクト名が表示される(例:[Ljava.lang.String;@5f184fc6)
More than 3 years have passed since last update.
Scanner.nextLine()で一行目の文字列を取得した後に、配列にして、目的の文字を要素で取得する方法
Last updated at Posted at 2021-05-24
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme