Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* At the first line at the console you are given a piece of text.
- * Extract all words from it and print them in alphabetical order.
- * Consider each non-letter character as word separator.
- * Take the repeating words only once. Ignore the character casing.
- * Print the result words in a single line, separated by spaces. */
- import java.util.Scanner;
- import java.util.TreeSet;
- public class _10_ExtractAllUniqueWords {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner scan = new Scanner(System.in);
- System.out.println("Enter your text on single line:");
- String inputLine = scan.nextLine().toLowerCase();
- String[] textStr = inputLine.split("[^a-z]+");
- TreeSet<String> extractWords = new TreeSet<>();
- for (String word : textStr) {
- extractWords.add(word);
- }
- System.out.println("The all Extract words in alphabetical order are:");
- for (String string : extractWords) {
- System.out.print(string + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement