回答編集履歴

1

Stream

2017/07/22 16:18

投稿

swordone
swordone

スコア20651

test CHANGED
@@ -29,3 +29,27 @@
29
29
  }
30
30
 
31
31
  ```
32
+
33
+ BufferedReader#lines()を使えばStreamになってもっと簡単に書けます。
34
+
35
+ ```java
36
+
37
+ public static void main(String[] args) {
38
+
39
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
40
+
41
+ int num = Integer.parseInt(br.nextLine());
42
+
43
+ String s = br.lines().limit(num).collect(Collectors.joining(",", "Hello ", "."));
44
+
45
+ System.out.println(s);
46
+
47
+ } catch (IOException e) {
48
+
49
+ e.printStackTrace();
50
+
51
+ }
52
+
53
+ }
54
+
55
+ ```