質問編集履歴

1

文法の修正

2018/10/09 14:09

投稿

Kobutachan
Kobutachan

スコア13

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,7 @@
1
+ お世話になっております。
2
+
3
+
4
+
1
5
  ユーザーに文字列を入れてもらい(A-Z,a-z,0-9, スペース、コンマetc)それをモールス信号化して表示するという課題です。
2
6
 
3
7
  アイデアとしてはハッシュマップを使って、入力された文字(キー)が見つかった場合その値を返すということを実現させたいです。
@@ -18,39 +22,21 @@
18
22
 
19
23
  public static void main(String[] args) {
20
24
 
25
+
26
+
21
- Scanner input = new Scanner(input);
27
+ HashMap<String, String> codes = new HashMap<String, String>();
22
28
 
23
29
 
24
30
 
31
+ Scanner input = new Scanner(System.in);
32
+
33
+
34
+
25
- System.out.println("文字列を入れてください");
35
+ System.out.println("Enter a string.");
26
36
 
27
37
  String str = input.nextLine();
28
38
 
29
- for (String line : str) {
30
-
31
- //文字列を一文字ずつに分ける
32
-
33
- String[] lineParts = line.split("");
34
-
35
- }
36
-
37
-
38
-
39
39
 
40
-
41
- HashMap<String, String> codes = new HashMap<Stirng, String>();
42
-
43
-
44
-
45
- getMorseChar = convert(str);
46
-
47
-
48
-
49
- }
50
-
51
-
52
-
53
- private static HashMap<>(String, String){
54
40
 
55
41
  codes.put("a",".-");
56
42
 
@@ -164,25 +150,45 @@
164
150
 
165
151
  codes.put("?","..--..");
166
152
 
167
- }
153
+
168
154
 
169
- public char getMorseCode() {
155
+ if(str.isEmpty()) {
170
156
 
171
- //inputとハッシュマップの比較
157
+ System.out.println("Please eneter a string.");
172
158
 
173
- }
159
+ }else {
160
+
161
+
162
+
163
+ String val = (String)codes.get(input);
174
164
 
175
165
 
166
+
167
+
168
+
169
+ System.out.println(str +" in morse code is " + val);
170
+
171
+ }
172
+
173
+
174
+
175
+
176
+
177
+ }
176
178
 
177
179
  }
178
180
 
179
181
 
180
182
 
183
+
184
+
185
+
186
+
187
+
188
+
181
189
  ```
182
190
 
183
- わからない点は、一文字ずつにわけた文字列をハッシュマップを使ってどのように探すのかというところです。
184
-
185
- getMorseCodeメソッドでその内容を遂げたと考えおり
191
+ エラーは実行しても nullが返されてしま、モールス信号が返っせん
186
192
 
187
193
 
188
194