c#程序控制台一个整数。在逆序输出!如123,输出则是321!写的越简单越好,一看就懂
c#程序控制台一个整数。在逆序输出!如123,输出则是321!写的越简单越好,一看就懂
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); } }
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); } }