您的位置:首页 > 其它

输入一串字符串,运用输出方法计算其中大写 小写 数字 和其他字符的个数

2016-04-01 17:21 1296 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class caclass
{

public static void ca(string s, out int a, out int b, out int c, out int d)
{
char[] nu = s.ToCharArray();
int x = 0, y = 0, z = 0, m = 0;
for (int i = 0; i < s.Length; i++)
{
if (nu[i] >= 'a' && nu[i] <= 'z')
{ x++; }
else if (nu[i] >= 'A' && nu[i] <= 'Z')
{ y++; }
else if (nu[i] >= '0' && nu[i] <= '9')
{ z++; }
else
{ m++; }

}

a = x;
b = y;
c = z;
d = m;

}

}
class Program
{

static void Main(string[] args)
{
Console.WriteLine("请输入一串字符:");
string s;
s = Console.ReadLine();
int zm, ZM, sz, qt;
caclass.ca(s, out zm, out ZM, out sz, out qt);
Console.WriteLine("您输入的字符串中大写字母的个数为:{0}", ZM);
Console.WriteLine("您输入的字符串中小写字母的个数为:{0}", zm);
Console.WriteLine("您输入的字符串中数字的个数为:{0}", sz);
Console.WriteLine("您输入的字符串中其他字符的个数为:{0}", qt);

Console.ReadKey();

}
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: