Question: What I need: Write a program named SortWords that includes a method named SortAndDisplayWords that accepts any number of words, sorts them in alphabetical order,

What I need:

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 funciton. The SortAndDisplayWords method will be tested with one, two, five, and ten words.

What I have:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace SortWords { class SortWords { public static void SortAndDisplayWords(int numWords) { string[] words = new string[numWords ];

for (int i = 0; i < numWords; i++) { Console.Write("Enter Word"+(i+1)+": "); words[i] = Console.ReadLine(); }

Console.WriteLine(" Before Sorting: ");

for (int i = 0; i < numWords; i++) { Console.Write(words[i]+" ");

}

Array.Sort(words);

Console.WriteLine(" After Sorting: ");

for (int i = 0; i < numWords; i++) { Console.Write(words[i] + " ");

}

} static void Main(string[] args) { int numWords; Console.Write("How many number of word(s) do you want accept: "); numWords = Convert.ToInt32(Console.ReadLine()); SortAndDisplayWords(numWords); Console.ReadKey(); } } }

Errors I have:

Build Status

Build Failed

Build Output

Compilation failed: 6 error(s), 0 warnings SortWords.cs(9,14): error CS1525: Unexpected symbol `void', expecting `class', `delegate', `enum', `interface', `partial', `ref', or `struct' SortWords.cs(11,0): error CS1525: Unexpected symbol `string', expecting `class', `delegate', `enum', `interface', `partial', `ref', or `struct' SortWords.cs(11,7): error CS1514: Unexpected symbol `[', expecting `.' or `{' SortWords.cs(11,7): error CS1525: Unexpected symbol `]', expecting `class', `delegate', `enum', `interface', `partial', `ref', or `struct' SortWords.cs(11,18): error CS1530: Keyword `new' is not allowed on namespace elements SortWords.cs(11,21): error CS1525: Unexpected symbol `string', expecting `class', `delegate', `enum', `interface', `partial', `ref', or `struct'

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!