I'm new to programming, and I am trying to write a program that take in an array of strings (each index of the array being a word) and then count the occurrences of each word in the string. This is what I have so far:
string[] words =
{
"which",
"wristwatches",
"are",
"swiss",
"wristwatches"
};
Array.Sort (words);
for (int i = 0; i < words.Length; i++)
{
int count = 1;
for(int j = 1; j < words.Length; j++)
{
if (words [i] == words [j])
{
count++;
}
}
Console.WriteLine ("{0} {1}", words[i], count);
}
Ideally, I would like the output to be something like:
are 1
swiss 1
which 1
wristwatches 2