您的位置:首页 > 其它

计算输入的字符串中字母,数字。。。的数量

2013-03-27 18:16 253 查看
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication2

{

    class Program

    {

        static void Main(string[] args)

        {

            Console.WriteLine("请输入一个字符串");

            string str = Console.ReadLine();

            char []b= str.ToCharArray();

            int up=0, low=0, dig=0, other=0;

            for (int i = 0; i < str.Length;i++ )

            {

                //Console.WriteLine(b[i]);

                if ('a' <= b[i]&& b[i] <= 'z')

                    low++;

                else if ('A' <= b[i]&&b[i]  <= 'Z')

                    up++;

                else if ('0'<=b[i] && b[i] <= '9')

                    dig++;

                else other++;

              

            }

            Console.WriteLine("小写字母有{0}个" ,low);

            Console.WriteLine("大写字母有{0}个", up);

            Console.WriteLine("数字有{0}个", dig);

            Console.WriteLine("其他字符有{0}个", other);

        }

    }

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