關于if的問題
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? string test;
? ? ? ? ? ? int i, j;
? ? ? ? ? ? test = Console.ReadLine();
? ? ? ? ? ? for(i=0,j=test.Length-1;i<=j;i++,j--)
? ? ? ? ? ? ? ? if (test[i] != test[j])
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? if(i<=j)
? ? ? ? ? ? ? ? ? ? Console.WriteLine("{0}不是回文串", test);
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? Console.WriteLine("{0}是回文串", test);
? ? ? ? }
? ? }
}
break后面用if(i<=j)不懂什么意思,如果我把他去掉然后讓下面的那句跟break合并又會有錯誤。求大神解答下
2018-08-21
這是老師的寫法誤導你了,
? if (test[i] != test[j])
{
? ? ? ? ? ? ? ? ? ? break;
}
?if(i<=j)
{
? Console.WriteLine("{0}不是回文串", test);
}
?else
{
?Console.WriteLine("{0}是回文串", test);
}
這樣看你明白了嗎