回答編集履歴
1
改正
test
CHANGED
@@ -99,3 +99,145 @@
|
|
99
99
|
}
|
100
100
|
|
101
101
|
```
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
コンストラクタの引数ごとに配列の長さを変えられるようにしたのが以下です
|
106
|
+
|
107
|
+
```java
|
108
|
+
|
109
|
+
class Test {
|
110
|
+
|
111
|
+
private int number = 1;
|
112
|
+
|
113
|
+
int[] x = new int[number];
|
114
|
+
|
115
|
+
int[] y = new int[number];
|
116
|
+
|
117
|
+
private int a = 10;
|
118
|
+
|
119
|
+
private int b = 30;
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
public Test(String name) {
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
switch (name) {
|
128
|
+
|
129
|
+
case "first":
|
130
|
+
|
131
|
+
this.number = 5;
|
132
|
+
|
133
|
+
x = new int[number];
|
134
|
+
|
135
|
+
for (int i = 0; i < number; i++) {
|
136
|
+
|
137
|
+
this.x[i] = a;
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
y = new int[number];
|
142
|
+
|
143
|
+
this.y[0] = b;
|
144
|
+
|
145
|
+
for (int i = 1; i < number; i++) {
|
146
|
+
|
147
|
+
this.y[i] = this.y[i - 1] + b;
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
break;
|
152
|
+
|
153
|
+
case "second":
|
154
|
+
|
155
|
+
this.number = 8;
|
156
|
+
|
157
|
+
x = new int[number];
|
158
|
+
|
159
|
+
for (int i = 0; i < number; i++) {
|
160
|
+
|
161
|
+
this.x[i] = a * 2;
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
y = new int[number];
|
166
|
+
|
167
|
+
this.y[0] = b * 3;
|
168
|
+
|
169
|
+
for (int i = 1; i < number; i++) {
|
170
|
+
|
171
|
+
this.y[i] = this.y[i - 1] + b * 3;
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
break;
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
class E2 {
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
public static void main(String[] args) {
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
Test a = new Test("first");
|
194
|
+
|
195
|
+
Test b = new Test("second");
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
for (int c : a.x) {
|
200
|
+
|
201
|
+
System.out.print(c + "-");
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
System.out.println();
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
for (int c : a.y) {
|
210
|
+
|
211
|
+
System.out.print(c + "-");
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
System.out.println();
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
for (int c : b.x) {
|
220
|
+
|
221
|
+
System.out.print(c + "-");
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
System.out.println();
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
for (int c : b.y) {
|
230
|
+
|
231
|
+
System.out.print(c + "-");
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
```
|