在c#中实现字符串的倒序输出和实现单词的倒序输出

本小白写了两个c#程序,一个是实现字符串的倒序输出(例如,把"How are you"变成"uoy era woH").第二个是实现单词的倒序输出(例如,把"How are you"变成"you are How",或者是把"我是 一个 弟弟"变成"弟弟 一个 我是")

第一个代码如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lianxi
{
    class Program
    {
        static void Main(string[] args)
        {
             int i;
             string s1=Console.ReadLine();
             //利用 ToCharArray()函数将字符串变成字符数组
             char[] s=s1.ToCharArray();               
             //然后利用 for循环将字符数组倒序输出
             for(i=s1.Length-1;i>=0;i--)
             {
                 Console.Write("{0}",s[i]);
             }
             Console.Readkey();
        }
    }    
}

如图
在这里插入图片描述
第二个代码如下

using System;
using System.Collection.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lianxi
{
    class Program
    {
        static void Main(string[] args)
        {
            string s1=Console.ReadLine();
            int i;
            //定义一个新的字符串数组,将用户输入的字符串从空格处分离开
            string[] s=s1.Split(' ');
            //用 for循环语句倒序输出字符串数组
            for(i=s.Length-1;i>=0;i--)
            {
                //在每个字符串中间加个空格
                console.Write(s[i]+' ');
            }
            Console.Readkey();
        }
    }
}

如图
在这里插入图片描述
这两个程序就是这样了,喵,为了学unity才学的c#,一起加油!

  • 4
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值