Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a console application that inputs a sentence from the user (assume no punc

ID: 3539043 • Letter: W

Question

Write a console application that inputs a sentence from the user (assume no punctuation), then determines and displays the non-duplicate words in alphabetical order. Treat uppercase and lowercase letters the same. [Hint: You can use string method Split with no arguments, as in sentence.Split(), to break a sentence into an array of strings containing the individual words. By default, Split uses spaces as delimiters. Use string method ToLower in the select and orderby clauses of your LINQ query to obtain the lowercase version of each word.]

Explanation / Answer

public static IEnumerable GetAlphabetizedUniqueWords(string sentence) { return (sentence ?? string.Empty) .Split() .Select(x => x.ToLowerInvariant()) .Distinct() .OrderBy(x => x); } static void Main( ) { Console.Write("Enter your sentence. No punctuation. : "); foreach (var word in GetAlphabetizedUniqueWords(Console.ReadLine())) Console.WriteLine(word); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote