c#编程数组逆序输出问题

来源:百度知道 编辑:UC知道 时间:2024/05/08 14:02:54
用户从键盘输入一个四位整数,如(1234);
(不能一个一个数分行输入,要一次性输入,最好用上%和/号)
然后逆序输出。如(4321);
谢谢

static void Main(string[] args)
{
Console.WriteLine("输入数字:");
string num=Console.ReadLine();
string newnum = "";
for (int i = num.Length-1; i >= 0; i--)
{
newnum += num[i];
}
Console.WriteLine(newnum);
}

string strResult="";
string strInt = Console.ReadLine();
for (int i = strInt.Length - 1; i > -1; i--)
{
strResult += strInt.Substring(i, 1);
}
Console.WriteLine(strResult);