using System;
namespace G09 {
class Reverse {
static void Main()
{
Console.WriteLine(ReverseText(24));
Console.ReadKey();
}
static string ReverseText(int n) {
if (n < 1)
{
return "";
}
string index = "1";
string revIndex = "";
int count = 1;
string[] arr = new string[n];
for (int i = 0; i < n; i++)
{
arr[i] = index + revIndex;
for (int j = 0; j <= i; j++)
{
if (count > 8)
{
index = index + 0;
count = 0;
break;
}
index = index + (count++ + 1).ToString();
break;
}
revIndex = "";
for (int k = index.Length - 1; k >= 0; k--)
{
if (k == index.Length - 1)
{
continue;
}
revIndex += index[k];
}
}
return string.Join("\n", arr);
}
}
}
Run Code Online (Sandbox Code Playgroud)
/tmp/csharp117013-18-5s54om.vh6mt2o6r/code.cs(10,41):警告CS0162:检测到无法访问的代码
谁能告诉我为什么这行代码在第23行无法访问?我无法理解...在视觉工作室它工作正常,但在其他节目错误.
这j++是毫无意义的,因为break在最后,删除其中之一
for (int j = 0; j <= i; j++) {
...
break;
}
Run Code Online (Sandbox Code Playgroud)
你永远不会增加j因为你break在第一个循环之后的迭代
for (int j = 0; j <= i; j++) //<- Error here, j++ will never be reached
{
if (count > 8)
{
index = index + 0;
count = 0;
break;
}
index = index + (count++ + 1).ToString();
break; //you leave the for loop here
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1812 次 |
| 最近记录: |