using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("请输入一个字符串:");
        string input = Console.ReadLine();

        int countA = 0, countE = 0, countI = 0, countO = 0, countU = 0;
        foreach (char c in input.ToLower())
        {
            switch (c)
            {
                case 'a':
                    countA++;
                    break;
                case 'e':
                    countE++;
                    break;
                case 'i':
                    countI++;
                    break;
                case 'o':
                    countO++;
                    break;
                case 'u':
                    countU++;
                    break;
            }
        }

        Console.WriteLine($"a:{countA}   e:{countE}   i:{countI}   o:{countO}   u:{countU}");
    }
}

运行程序后,输入一个字符串,程序会统计其中每个元音字母出现的次数,并输出结果

C#:任务一:输入一个字符串统计每个元音字母aeiou在字符串中出现的次数。例如输入aeioubbbccc输出:a1 e1 i1 o1 u1要求:利用String对象对字符串进行操作。30分

原文地址: https://www.cveoy.top/t/topic/iLG7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录