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

回答編集履歴

1

追記

2017/09/01 15:55

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -54,4 +54,39 @@
54
54
  ```
55
55
 
56
56
  本質的な回答とはちょっと違いますので、参考程度に見てみてください。
57
- ただし、**インデントはちゃんと揃えましょう**。
57
+ ただし、**インデントはちゃんと揃えましょう**。
58
+
59
+ ---
60
+ 元のプログラムをある程度維持するとこんな感じ。
61
+ ```Java
62
+ import java.util.Scanner;
63
+ public class Average{
64
+ public static void main(String[]args){
65
+ Scanner sc = new Scanner(System.in);
66
+ int[] result = new int[100];
67
+
68
+ int resultNum = 0;
69
+ while(sc.hasNext()){
70
+ int n=sc.nextInt();
71
+ if(n==0) {break;}
72
+ int[]a=new int[n];
73
+ for(int i=0; i<n; i++) a[i]=sc.nextInt();
74
+ int x=0;
75
+ for(int i=0; i<n; i++){
76
+ x=x+a[i];
77
+ }
78
+
79
+ result[resultNum] = x/n;
80
+ result++;
81
+ }
82
+
83
+ // 出力
84
+ for(int j = 0; j < 100; j++) { if(result[j] == 0)
85
+ break;
86
+ System.out.println(result[j]);
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ インデントを意図的に崩し、わざと冗長な方法を用いてみました。