oj 3445 c#统计字符串中数字字符的个数

题目描述

假设有一个GetNumber方法(参数为字符串strSource),编写一个静态方法可以用来统计字符串strSource中数字字符的个数。

输入

输入一个字符串strSource

输出

strSource字符串中数字字符的个数

using System;
using System.IO;
using System.Globalization;
using System.Security.Cryptography;
using System.Text;

namespace myApp
{
    class Program
    {

        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            GetNumber(s);

        }



        public static void GetNumber(string setSource)
        {
            char[] a = setSource.ToCharArray();
            int total = 0;
            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] >= 48 && a[i] <= 57)
                {
                    total++;
                }
            }
            Console.WriteLine(total);
        }
    }

}

发布了14 篇原创文章 · 获赞 14 · 访问量 648

猜你喜欢

转载自blog.csdn.net/weixin_46292455/article/details/104931688