`

华智公司一道面试题

阅读更多

    //说明:例如:
    //数字123->变成00000123
    //123456789->变成23456789
    class Program
    {
        static void Main(string[] args)
        {
            //用户随便输入一个字符串
            string s = Console.ReadLine();
            //长度大于8
            if (s.Length>=8)
            {
                s = s.Substring(s.Length - 8, 8);
            }
          
            //小于8的长度
            else if (s.Length < 8)
            {
                string adds=null;
                for (int i = 0; i < 8-s.Length; i++)
                {
                    adds += "0";
                }
                s = adds +  s;
            }

            Console.WriteLine(s);
            Console.ReadKey();
        }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics