-
Notifications
You must be signed in to change notification settings - Fork 213
Expand file tree
/
Copy pathStringSort.java
More file actions
48 lines (38 loc) · 946 Bytes
/
StringSort.java
File metadata and controls
48 lines (38 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.util.*;
import javax.swing.*;
class StringSort {
public static void main(String[] args)
{
String[] values = new String[15];
int x = 0;
int count = 0;
String word;
final String QUIT = "zzz";
boolean didUserQuit = false;
for(x = 0; x < values.length; ++x)
values[x] = QUIT;
x = 0;
while(x < values.length)
{
word = JOptionPane.showInputDialog(null, "Enter a word or " + QUIT + " to quit");
if(word.equals(QUIT))
{
count = x;
x = values.length;
didUserQuit = true;
}
else
{
values[x] = word;
++x;
}
}
if(!didUserQuit)
count = values.length;
String message = "Values:";
Arrays.sort(values);
for(x=0; x < count; ++x)
message = message + " " + values[x];
JOptionPane.showMessageDialog(null, message);
}
}