求高手指点,给个解决方法???
我是个C#新手,现求各位大哥大姐帮帮忙条件:
用户随便输入一个8位以下的整数
要求:
输出结果为倒序排列
假如用户输入的数是12345678
那么程序运行结果要求是87654321
程序代码:using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
string str="";//输入
string str1="";//输出
Console.WriteLine("输入一个小于8位的整数:");
while ((str = Console.ReadLine()) != null)
{
str1 = "";//清空
try
{
int.Parse(str);//判断是否整数
if (str.Length > 8)//判断长度
{
Console.WriteLine("整数过长!");
}
char[] ch = str.ToCharArray();//分成字符流
Array.Reverse(ch);//倒序
foreach (char a in ch)//拼接
{
str1 += a.ToString();
}
Console.WriteLine("整数反序是:{0}", str1);//输出
}
catch
{
Console.WriteLine("输入有误!");
}
Console.WriteLine("输入一个小于8位的整数:");
}
}
}
}
