接收用户输入的一句英文,将其中的单词以反序输出。 例如:“Hello C sharp”→“olleH C prahS”
string str = "Hello C Sharp";
string[] str1 = str.Split(' ');
//Console.WriteLine(str1.Length);
string s = "";
string a = "";
for (int i = str1.Length-1; i >= 0; i--)
{
s = s+ str1[i];
// Console.WriteLine(s);
}
for (int j = s.Length-1; j >= 0; j--)
{
a = a + s[j];
}
string hh1 = a.Substring(0,5);
string hh2 = a.Substring(5,1);
string hh3 = a.Substring(6,5);
Console.WriteLine(hh1+" "+hh2+" "+hh3+" 你好");
string[] str2 = s.Split(' ');
Console.WriteLine(s);
Console.ReadKey();
}
还有更好的方法吗? |
|