teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

追記

2017/12/27 11:41

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -6,10 +6,19 @@
6
6
 
7
7
  String array[] = sc.nextLine().split(" ");
8
8
  System.out.println(Arrays.asList(array));
9
+
10
+ sc.close();
9
11
  ```
10
12
 
13
+ Scannerをインスタンス化する場合、最後にcloseしてあげるのを忘れないでください。
14
+
15
+ ---
11
16
  なお、こんな質問を見つけたのでご紹介しておきます。
12
17
  こちらでは、また別の解法も回答されています。
13
18
  [StackOverflow
14
19
  Scanner is skipping nextLine() after using next(), nextInt() or other nextFoo()?
15
- ](https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-nextint-or-other-nextfoo)
20
+ ](https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-nextint-or-other-nextfoo)
21
+
22
+ nextで上手くいく理由
23
+ ---
24
+ [Scanner#next](https://docs.oracle.com/javase/jp/8/docs/api/java/util/Scanner.html#next--)は、**有効なトークン**を読み込んでくれるようです。

2

成形

2017/12/27 11:41

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -10,5 +10,6 @@
10
10
 
11
11
  なお、こんな質問を見つけたのでご紹介しておきます。
12
12
  こちらでは、また別の解法も回答されています。
13
+ [StackOverflow
13
- [StackOverflow - Scanner is skipping nextLine() after using next(), nextInt() or other nextFoo()?
14
+ Scanner is skipping nextLine() after using next(), nextInt() or other nextFoo()?
14
15
  ](https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-nextint-or-other-nextfoo)

1

追記

2017/12/27 11:18

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -6,4 +6,9 @@
6
6
 
7
7
  String array[] = sc.nextLine().split(" ");
8
8
  System.out.println(Arrays.asList(array));
9
- ```
9
+ ```
10
+
11
+ なお、こんな質問を見つけたのでご紹介しておきます。
12
+ こちらでは、また別の解法も回答されています。
13
+ [StackOverflow - Scanner is skipping nextLine() after using next(), nextInt() or other nextFoo()?
14
+ ](https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-nextint-or-other-nextfoo)