回答編集履歴

1

IntSummaryStatistics

2018/05/17 15:07

投稿

swordone
swordone

スコア20651

test CHANGED
@@ -1,3 +1,35 @@
1
1
  - そもそも本当に「コンパイルがうまくいかない」のか?実行時エラーではなくて?
2
2
 
3
3
  - なんでScannerを5回も生成しているのか
4
+
5
+
6
+
7
+ せっかくなので、Java8からの新クラスを紹介
8
+
9
+ [IntSummaryStatistics](https://docs.oracle.com/javase/jp/8/docs/api/java/util/IntSummaryStatistics.html)
10
+
11
+
12
+
13
+ ```java
14
+
15
+ public static void main(String[] args) {
16
+
17
+ IntSummaryStatistics summary = new IntSummaryStatistics();
18
+
19
+ try (Scanner sc = new Scanner(System.in)) {
20
+
21
+ while (sc.hasNextInt()) {
22
+
23
+ summary.accept(sc.nextInt());
24
+
25
+ }
26
+
27
+ }
28
+
29
+ System.out.println("最大値: " + summary.getMax());
30
+
31
+ System.out.println("最小値: " + summary.getMin());
32
+
33
+ }
34
+
35
+ ```