注册 登录
编程论坛 C# 论坛

求大神解答,如果一个数首位是0,怎样可以把包括0的这个数输出来如果输入5217,结果该是0641,而我是641

等等等 发布于 2015-06-17 10:47, 672 次点击
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string st;
            st=Console.ReadLine();
            int x,a,b,c,d;
            x = Convert.ToInt32(st);
            a = (x % 10 + 9) % 10;
            b = (x / 10 % 10 + 9) % 10;
            c = (x / 100 % 10 + 9) % 10;
            d = (x /1000 % 10 + 9) % 10;
            x = b * 1000 + a * 100 + d * 10 + c;
            Console.WriteLine("{0}", x);
            Console.ReadLine();

           
        }
    }
}
如果输入5217,结果该是0641,而我是641
3 回复
#2
Maick2015-06-17 15:24
换成字符串
#3
wangnannan2015-06-18 13:00
因为x是int型呗 基础问题看书
#4
靠谱懒人2015-06-22 15:59
Console.WriteLine(x.ToString("0000"));
1