-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath4.java
More file actions
34 lines (23 loc) · 1.02 KB
/
Copy pathMath4.java
File metadata and controls
34 lines (23 loc) · 1.02 KB
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
public class Math4 {
public static void main(String[] args){
String text = "To be or not to be, that is the question; "
+ "Whether `tis nobler in the mind to suffer "
+ "the slings and arrows of outrageous fortune, "
+ "or to take arms against a sea of troubles, "
+ "and by opposing end them?";
String[] words = text.split("[\\s\\p{Punct}]+");
for (int i = 0; i < words.length - 1; i++) {
for (int j = 0; j < words.length - i - 1; j++) {
if (words[j].compareToIgnoreCase(words[j + 1]) > 0) {
String temp = words[j];
words[j] = words[j + 1];
words[j + 1] = temp;
}
}
}
System.out.println("Sorted words:");
for (String word : words) {
System.out.println(word);
}
}
}