質問編集履歴
2
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
import java.util.Scanner;
|
11
11
|
|
12
12
|
|
13
|
+
|
13
14
|
public class PostalCode {
|
14
15
|
|
15
16
|
public static void main(String[] args) {
|
@@ -23,19 +24,19 @@
|
|
23
24
|
Scanner str = new Scanner(System.in);
|
24
25
|
int yuubin = str.nextInt();
|
25
26
|
|
27
|
+
String address = map.get(yuubin);
|
28
|
+
map.put(yuubin, address);
|
29
|
+
|
26
|
-
System.out.println(yuubin+ "に対応する住所は" +
|
30
|
+
System.out.println(yuubin+ "に対応する住所は" +address+ "です。");
|
27
31
|
|
28
32
|
} catch (FileNotFoundException e) {
|
29
33
|
System.out.println("ファイルが見つかりません");
|
30
|
-
|
34
|
+
}
|
31
35
|
}
|
32
36
|
|
33
37
|
}
|
34
38
|
|
35
|
-
}
|
36
39
|
|
37
|
-
}
|
38
|
-
|
39
40
|
```
|
40
41
|
実行結果
|
41
42
|
```
|
1
書式の改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
HashMapを使いたいのですがgetではダメなんでしょうか?
|
6
6
|
```
|
7
7
|
import java.io.File;
|
8
|
+
import java.io.FileNotFoundException;
|
8
9
|
import java.util.HashMap;
|
9
10
|
import java.util.Scanner;
|
10
11
|
|
@@ -14,17 +15,27 @@
|
|
14
15
|
public static void main(String[] args) {
|
15
16
|
File fr = new File("postalcode.csv");
|
16
17
|
|
17
|
-
HashMap<Integer, String> map = new HashMap<Integer, String>();
|
18
18
|
|
19
|
+
try (Scanner fin = new Scanner(fr)) {
|
20
|
+
HashMap<Integer, String> map = new HashMap<Integer, String>();
|
21
|
+
|
19
|
-
|
22
|
+
System.out.print("郵便番号:");
|
20
|
-
|
23
|
+
Scanner str = new Scanner(System.in);
|
21
|
-
|
24
|
+
int yuubin = str.nextInt();
|
22
|
-
|
25
|
+
|
23
|
-
|
26
|
+
System.out.println(yuubin+ "に対応する住所は" +map.get(yuubin)+ "です。");
|
27
|
+
|
28
|
+
} catch (FileNotFoundException e) {
|
29
|
+
System.out.println("ファイルが見つかりません");
|
30
|
+
}
|
24
31
|
}
|
25
32
|
|
26
33
|
}
|
27
34
|
|
35
|
+
}
|
36
|
+
|
37
|
+
}
|
38
|
+
|
28
39
|
```
|
29
40
|
実行結果
|
30
41
|
```
|