Console.WriteLine(“请输入一段字符”);
string c = Console.ReadLine();
//数组的索引是从0开始的,所以长度减去一
//这个是获取总的索引长度的
int len = c.Length - 1;
//第一个数
int x;
//最后一个数
int y;
for (x = 0, y = len - x; x <= (len + 1) / 2; ++x, --y)
{
if (c[x] != c[y])
{
Console.WriteLine(“不是回文”);
break;
}
}
if (x >= y)
{
Console.WriteLine(“是回文”);
}
Console.ReadKey();
c#中如何判断是否为回文数
最新推荐文章于 2023-12-11 10:02:20 发布