using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Day019
{
class Program
{
static void Main(string[] args)
{
//请将字符串"I am a student"按单词逆序输出 如"student a am I"
String s = "I am a student ."; //输入要打逆序打印的东西
char[] c = new char[] {' '}; //创建一个char 类型的数组,接收打印的片段
String[] n = s.Split(c); //Split()方法破坏单词(拆解单词为单个字母)
for (int i = n.Length - 1; i >=0; i--)//逆序打印
{
Console.Write(n[i]);
if (i !=0) //当判断一个单词内打印完字母了加个空格
{
Console.Write(" ");
}
}
Console.ReadLine();
}
}
}
c#逆序打印“I am a student“
于 2022-03-28 21:05:49 首次发布