예제 #1
0
        public static void Main()
        {
            RepeatCounter countMe = new RepeatCounter();

            Console.WriteLine("please enter a sentence:");
            string sentence = Console.ReadLine();

            Console.WriteLine("please enter a word: ");
            string word  = Console.ReadLine();
            bool   valid = countMe.Validator(word);

            if (valid == false)
            {
                Console.WriteLine("The word you entered is not a word.");
            }
            else if (countMe.ContainsWord(sentence, word) && (countMe.HowMany(sentence, word)) > 0)
            {
                int num = countMe.HowMany(sentence, word);
                Console.WriteLine("The sentence '" + sentence + "' contains " + num + " instances of the word '" + word + "'.");
            }
            else
            {
                Console.WriteLine("There are no instances of " + word + " in your sentence.");
            }
        }