0
0

More than 3 years have passed since last update.

Scanner.nextLine()で一行目の文字列を取得した後に、配列にして、目的の文字を要素で取得する方法

Last updated at Posted at 2021-05-24
// 入力例: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)
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