學校題目 不會做 求1個完整的代碼用C#做例如寫入1,它會顯示001
        10,顯示010希望各位大大速度幫幫忙

解决方案 »

  1.   


    public string Csdn(string str)
        {
            string newStr = string.Empty;
            int i = str.Length;
            if (i < 3)
            {
                for (int j = 0; j < 3-i; j++)
                {
                    newStr += "0" ;
                }
            }
            newStr += str; 
            return newStr;
        }
      

  2.   

    using System;
    class Test 
    {
        static void Main(){
        string strOut;
        string strIn;    Console.Write("请输入:");
        strIn = Console.ReadLine();
        strOut = string.Format("{0:D3}", Int32.Parse(strIn));
        Console.Write("输入的是:" + strOut);
        Console.ReadLine();
        }

    没有做非数字的检查哦。
      

  3.   

    string s=Console.ReadLine();
    Console.WriteLine(s.PadLeft(3,'0'));