当前位置: 代码迷 >> 综合 >> c#逆序打印“I am a student“
  详细解决方案

c#逆序打印“I am a student“

热度:69   发布时间:2023-12-06 14:53:35.0
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();}}
}

  相关解决方案