Reverse word of full sentence

后端 未结 16 1924
眼角桃花
眼角桃花 2020-12-06 20:04

I want to print string in reverse format:

Input: My name is Archit Patel

Output: Patel Archit is name My.

I\'ve tied the

16条回答
  •  半阙折子戏
    2020-12-06 20:41

    namespace Reverse_the_string
    {
        class Program
        {
            static void Main(string[] args)
            {
    
               // string text = "my name is bharath";
                string text = Console.ReadLine();
                string[] words = text.Split(' ');
                int k = words.Length - 1;
                for (int i = k;i >= 0;i--)
                {
                    Console.Write(words[i] + " " );
    
                }
    
                Console.ReadLine();
    
            }
        }
    }
    

提交回复
热议问题