C# Count Vowels

后端 未结 17 1762
小鲜肉
小鲜肉 2020-12-03 08:59

I am learning to program C# and I am trying to count the vowels. I am getting the program to loop through the sentence, but instead of returning vowel count, it is just retu

17条回答
  •  天涯浪人
    2020-12-03 09:40

    Maybe too advanced for a starter, but this is the way you do that in C#:

    var vowels = new[] {'a','e','i','o','u'};
    
    Console.WriteLine("Enter a Sentence");
    var sentence = Console.ReadLine().ToLower();
    
    var vowelcount = sentence.Count(x => vowels.Contains(x));
    
    Console.WriteLine("Your total number of vowels is: {0}", vowelcount);
    Console.ReadLine();
    

提交回复
热议问题