C# i need to Write a program named SortWords that includes a method named SortAndDisplayWords that accepts any number of words, sorts them in alphabetical order, and displays the sorted words separated by spaces. Write a Main() to test this function. The SortAndDisplayWords method will be tested with one, two, five, and ten words. Method SortAndDisplayWords sorts and displays one word Method SortAndDisplayWords sorts and displays two words Method SortAndDisplayWords sorts and displays ten wordsMethod SortAndDisplayWords sorts and displays five words using System; using static System.Console; public class SortWords { public static void Main() { // Write your main here } public static void SortAndDisplayWords(params string[] words) { } }
C#
i need to Write a program named SortWords that includes a method named SortAndDisplayWords that accepts any number of words, sorts them in alphabetical order, and displays the sorted words separated by spaces.
Write a Main() to test this function. The SortAndDisplayWords method will be tested with one, two, five, and ten words.
Method SortAndDisplayWords sorts and displays one word
Method SortAndDisplayWords sorts and displays two words

CODE in C#:
using System;
using static System.Console;
public class SortWords
{
public static void Main()
{
SortAndDisplayWords("one");
SortAndDisplayWords("one", "two");
SortAndDisplayWords("five", "ten", "one", "two", "three");
SortAndDisplayWords("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten");
}
public static void SortAndDisplayWords(params string[] words)
{
Array.Sort(words);
WriteLine(string.Join(" ", words));
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps









