c#程序控制台一个整数。在逆序输出!如123,输出则是321!写的越简单越好,一看就懂
c#程序控制台一个整数。在逆序输出!如123,输出则是321!写的越简单越好,一看就懂
2010-10-24 17:39
2010-10-24 18:04
程序代码: class Program
{
static void Main(string[] args)
{
int a = 123;
int b = 0;
while (a > 0)
{
b = b * 10 + a % 10;
a /= 10;
}
Console.WriteLine(b);
}
}

2010-10-24 18:18
2010-10-24 18:33
2010-10-24 19:12
2010-10-25 01:14

程序代码:using System;
using System.Collections.Generic;
class Program
{
static void Main(string[] args)
{
int a = 1234567;
char[] b = a.ToString().ToCharArray();
Array.Reverse(b);
string c = new string(b);
Console.WriteLine(c);
}
}
如果不知道Array.Reverse()的用法,那么还可以这么做
程序代码:using System;
class Program
{
static void Main(string[] args)
{
int a = 1234567;
char[] b = a.ToString().ToCharArray();
int c = b.Length / 2;
for (int i = 0; i < c; i++)
{
char tmp = b[i];
int d = b.Length - i - 1;
b[i] = b[d];
b[d] = tmp;
}
string e = new string(b);
Console.WriteLine(e);
}
}

2010-10-25 08:28
2010-10-25 09:20
2010-10-26 19:01
2010-10-27 16:21