高分求, C#题一道

来源:百度知道 编辑:UC知道 时间:2024/05/02 16:15:07
将字符串"I am a student"按单词逆序输出 如"student a am I"
~~~~你们让我很失望。
string Str="I am a student";
string []strArr = Str.Split(' ');
string resultStr="";
for (int j = strArr.Length-1; j >= 0; j--)
{
resultStr += strArr[j] + " ";
}
Response.Write(resultStr);

//逆序输出字符串

using System;

class Output
{
public static void Main(string[] args)
{
int i = 0;
string Tem = null, strold = null;
for (i = 0; i < args.Length; i++)
{
strold += args[i] + " "; //将用户输入的字符串记录下来
foreach (char chr in args[i].ToCharArray())
{
Tem = chr + Tem; //逐个字符逆序并送给出Tem变量
}
Tem = " " + Tem; //在每个字符串前加空格(为什么呢?大家肯定知道啦啦)
}
Console.WriteLine("You said : {0}", strold); //输出原字符串
Console.WriteLine("But I say : {0}", Tem); //逆序后输出
}
}

/*
* 输入: abc def
* 输出: fed cba
*/

using System;
using System.Collections.Generic