質問編集履歴
1
質問内容の変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
キーボードから英単語を入力し、HashSetを持ちいて、アルファベット順に表記したいです。
|
test
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
|
1
|
+
下記のコードを書いてみました。よろしくお願いします。
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
import
|
5
|
+
import java.util.*;
|
6
6
|
|
7
|
-
public
|
7
|
+
public class Main{
|
8
8
|
|
9
|
-
|
9
|
+
public static void main(String[] args) throws IOException {
|
10
10
|
|
11
|
-
|
11
|
+
InputStreamReder isr=new InputStreamReader(System.ini);
|
12
12
|
|
13
|
-
|
13
|
+
BufferReader br=new BufferReader(isr);
|
14
14
|
|
15
|
+
String buf=br.readLine();
|
16
|
+
|
15
|
-
HashSet<String>
|
17
|
+
HashSet<String> hs=new HashSet<String>();
|
16
18
|
|
17
19
|
while(true){System.out.println("入力してください:");
|
18
20
|
|
@@ -22,22 +24,26 @@
|
|
22
24
|
|
23
25
|
}
|
24
26
|
|
25
|
-
/*
|
27
|
+
/* String str="apple"; */
|
26
28
|
|
27
|
-
String[]
|
29
|
+
String[] buf=str.split("");
|
28
30
|
|
29
|
-
for(int
|
31
|
+
for(int i=0; i<buf.length; i++){
|
30
32
|
|
31
33
|
hs.add(buf[i]);
|
32
34
|
|
33
|
-
/*
|
35
|
+
/* System.out.print(" "+buf[i]; */
|
34
36
|
|
35
37
|
}
|
36
38
|
|
37
|
-
/*
|
39
|
+
/* for(String s: hs){System.out.print(s);} */
|
38
40
|
|
39
|
-
List<String>
|
41
|
+
List<String> li=ArrayList<String>(hs);
|
40
42
|
|
41
43
|
Collections.sort(li);
|
42
44
|
|
43
|
-
for(String
|
45
|
+
for(String t: li){System.out.print(t);}
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
}
|