回答編集履歴
1
追記
test
CHANGED
@@ -111,3 +111,73 @@
|
|
111
111
|
本質的な回答とはちょっと違いますので、参考程度に見てみてください。
|
112
112
|
|
113
113
|
ただし、**インデントはちゃんと揃えましょう**。
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
---
|
118
|
+
|
119
|
+
元のプログラムをある程度維持するとこんな感じ。
|
120
|
+
|
121
|
+
```Java
|
122
|
+
|
123
|
+
import java.util.Scanner;
|
124
|
+
|
125
|
+
public class Average{
|
126
|
+
|
127
|
+
public static void main(String[]args){
|
128
|
+
|
129
|
+
Scanner sc = new Scanner(System.in);
|
130
|
+
|
131
|
+
int[] result = new int[100];
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
int resultNum = 0;
|
136
|
+
|
137
|
+
while(sc.hasNext()){
|
138
|
+
|
139
|
+
int n=sc.nextInt();
|
140
|
+
|
141
|
+
if(n==0) {break;}
|
142
|
+
|
143
|
+
int[]a=new int[n];
|
144
|
+
|
145
|
+
for(int i=0; i<n; i++) a[i]=sc.nextInt();
|
146
|
+
|
147
|
+
int x=0;
|
148
|
+
|
149
|
+
for(int i=0; i<n; i++){
|
150
|
+
|
151
|
+
x=x+a[i];
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
result[resultNum] = x/n;
|
158
|
+
|
159
|
+
result++;
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
// 出力
|
166
|
+
|
167
|
+
for(int j = 0; j < 100; j++) { if(result[j] == 0)
|
168
|
+
|
169
|
+
break;
|
170
|
+
|
171
|
+
System.out.println(result[j]);
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
インデントを意図的に崩し、わざと冗長な方法を用いてみました。
|