Compare commits

..

No commits in common. "531238a9353cdb835aa8f15d07e07865846e7326" and "fc4a97f8eaf61905ae0fda353f83c5e48bfe3237" have entirely different histories.

1 changed files with 5 additions and 3 deletions

View File

@ -25,17 +25,19 @@ public class Sentence {
allWords.append(sentence).append(" "); allWords.append(sentence).append(" ");
} }
String[] words = allWords.toString().split("\\W+"); String[] words = allWords.toString().split("\\W+"); // Remove punctuation marks
HashSet<String> uniqueWords = new HashSet<>(); HashSet<String> uniqueWords = new HashSet<>();
for (String word : words) { for (String word : words) {
uniqueWords.add(word.toLowerCase()); if (!word.isEmpty()) { // Ignore empty words
uniqueWords.add(word.toLowerCase()); // Convert word to lowercase and add to HashSet
}
} }
String[] uniqueSortedWords = uniqueWords.toArray(new String[0]); String[] uniqueSortedWords = uniqueWords.toArray(new String[0]);
Arrays.sort(uniqueSortedWords); Arrays.sort(uniqueSortedWords); // Sort unique words by the first letter
for (String word : uniqueSortedWords) { for (String word : uniqueSortedWords) {
System.out.println(word); System.out.println(word);