svetlozar_kirkov

Reverse words ordering (Exercise)

Oct 10th, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleTests
  4. {
  5.     class ConsoleTests
  6.     {
  7.         static void Main()
  8.         {
  9.             string text = Console.ReadLine();
  10.             Console.WriteLine(ReverseWords(text));
  11.         }
  12.         public static string ReverseWords(string sentence)
  13.         {
  14.             char[] separators = new char[2]{' ','.'};
  15.             string[] words = sentence.Split(separators);
  16.             Array.Reverse(words);
  17.             return string.Join(" ", words);
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment