所谓回文,是指从左到右念跟从右到左念是一样的,例如:1223221,yujajuy,以下是判断回文的算法
public static void JudgePalindrome (string teststring)
{
for (int i = 0; i < teststring.Length - 1; i++)
{
if (teststring[i] != teststring[teststring.Length - i - 1])
{ Console.WriteLine("It is palindrome");
}
else
{
Console.WriteLine("It is not palindrome");
}
}
}
判断成功后,输出了很多句It is palindrome或者是It is not palindrome,怎样让它判断完成之后就只输出一句It is palindrome或者是It is not palindrome呢
public static void JudgePalindrome (string teststring)
{
for (int i = 0; i < teststring.Length - 1; i++)
{
if (teststring[i] != teststring[teststring.Length - i - 1])
{ Console.WriteLine("It is palindrome");
}
else
{
Console.WriteLine("It is not palindrome");
}
}
}
判断成功后,输出了很多句It is palindrome或者是It is not palindrome,怎样让它判断完成之后就只输出一句It is palindrome或者是It is not palindrome呢
解决方案 »
- C#中的string到底是什么类型?
- 求教,求指点....怎么把进程窗口显示并前置?
- 再发一贴,为什么别人能实现的效果我实现不了?(解决立刻给分)
- 一个较偏僻的技术问题,求高手解答
- Winform中嵌入别的程序界面的问题
- 请问什么是数据库的连接池?一般有什么用?
- 各位做程序的前辈们,给晚辈指指路。。。。
- treeview如何判断一个结点下面是否还有子结点?
- DirectoryEntry可以对相应路径下的对象进行遍历,DirectorySearcher可以进实例的DiretoryEntry进行搜索,二者有什么区别吗?
- 多文件(无物理地址)下载 .NET
- 如何学习.net
- SQL server Data ----> XML
{
public static bool JudgePalindrome(string teststring)
{
bool flag = true ;
for (int i = 0; i < teststring.Length - 1; i++)
{
if (teststring[i] != teststring[teststring.Length - i - 1])
{
flag = false;
break;
}
}
return flag;
} public static void Main(string[] args)
{
bool flag = JudgePalindrome("aba"); if(flag)
Console.WriteLine("It is palindrome");
else
Console.WriteLine("It is not palindrome");
}
}