控制台程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace test3_2
{
class Program
{
static void Main(string[] args)
{
int[] charNum = new int[26];
int other;
int i;
char temp;
string strTest;
for (i = 0; i < 26; i++)
{
charNum[i] = 0;
}
other = 0;
Console.WriteLine("请输入要统计的字符串");
strTest = Console.ReadLine();
strTest = strTest.ToUpper();
Console.WriteLine("字符出现次数");
for (i = 0; i < strTest.Length; i++)
{
temp = strTest[i];
if (temp >= 'A' && temp <= 'Z')
{
charNum[temp - 'A']++; // 分类统计
}
else
{
other++;
}
}
for (i = 0; i < 26; i++)
{
if (charNum[i] != 0)
{
Console.WriteLine("{0} has {1}",(char)(i+'a'),charNum[i]);
}
}
Console.WriteLine("other has {0}", other);
Console.ReadLine();
}
}
}