30
2012
03

C# Winfrom中逆序输出数字

using System;
class Program
{
static void Main(string[] args)
{
int n;
while (!int.TryParse(Console.ReadLine(), out n))
Console.WriteLine("try again");
StringBuilder sa = new StringBuilder();
string s = n.ToString();
for (int i = s.Length-1; i > -1; i--)
sa.Append(s[i]);
Console.WriteLine("result " + sa.ToString());
}
}

using System;
class Program
{
static void Main(string[] args)
{
int m, n = 0, r;
m = Convert.ToInt16( Console.ReadLine());
while (m != 0)
{
r = m % 10;
n = n * 10 + r;
m = m / 10;
}
Console.WriteLine(n);
}
}
« 上一篇下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。