回答編集履歴
1
変更
answer
CHANGED
@@ -1,41 +1,38 @@
|
|
1
1
|
```java
|
2
|
-
String name[] = { "田中", "加藤", "森田", "北国" };
|
3
|
-
|
2
|
+
public static void main(String[] args) throws Exception {
|
4
3
|
|
5
|
-
|
4
|
+
String name[] = { "田中", "加藤", "森田", "北国" };
|
5
|
+
String test[] = { "国語", "英語", "理科", "社会" };
|
6
6
|
|
7
|
-
|
7
|
+
int point[][] = { { 100, 80, 50, 30 }, { 30, 40, 70, 90 }, { 50, 90, 100, 0 }, { 0, 10, 70, 30 } };
|
8
8
|
|
9
|
-
System.
|
9
|
+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
10
|
-
String strx = br.readLine();
|
11
10
|
|
12
|
-
System.out.println("
|
11
|
+
System.out.println("名前を入力してください");
|
13
|
-
String
|
12
|
+
String strx = br.readLine();
|
14
13
|
|
15
|
-
int nameIndex = -1;
|
16
|
-
|
14
|
+
System.out.println("科目を入力してください");
|
17
|
-
|
15
|
+
String stry = br.readLine();
|
18
|
-
nameIndex = i;
|
19
|
-
break;
|
20
|
-
}
|
21
|
-
}
|
22
16
|
|
23
|
-
|
17
|
+
int nameIndex = index(name, strx);
|
24
|
-
|
18
|
+
int testIndex = index(test, stry);
|
19
|
+
|
20
|
+
System.out.println("名前:" + strx);
|
21
|
+
System.out.println(stry + ":" + point[nameIndex][testIndex]);
|
25
22
|
}
|
26
23
|
|
24
|
+
private static int index(String[] array, String value) {
|
27
|
-
int
|
25
|
+
int index = -1;
|
28
|
-
for (int i = 0; i <
|
26
|
+
for (int i = 0; i < array.length; i++) {
|
29
|
-
|
27
|
+
if (value.equals(array[i])) {
|
30
|
-
|
28
|
+
index = i;
|
31
|
-
|
29
|
+
break;
|
30
|
+
}
|
32
31
|
}
|
32
|
+
if (index == -1) {
|
33
|
+
throw new IllegalArgumentException(value);
|
33
|
-
}
|
34
|
+
}
|
34
35
|
|
35
|
-
|
36
|
+
return index;
|
36
|
-
throw new IllegalArgumentException(stry);
|
37
37
|
}
|
38
|
-
|
39
|
-
System.out.println("名前:" + strx);
|
40
|
-
System.out.println(stry + ":" + point[nameIndex][testIndex]);
|
41
38
|
```
|