elena1234

RandomizeWords

Sep 25th, 2020 (edited)
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. namespace randomizeWords
  4. {
  5.     class MainClass
  6.     {
  7.         public static void Main()
  8.         {
  9.             var rnd = new Random();
  10.             var words = Console.ReadLine().Split().ToArray();
  11.  
  12.             for (int i = 0; i < words.Length; i++)
  13.             {
  14.                 var randomIndex = rnd.Next(0, words.Length);
  15.  
  16.                 var a = words[randomIndex];
  17.                 var b = words[i];
  18.              
  19.                 words[randomIndex] = b;
  20.                 words[i] = a;
  21.             }
  22.  
  23.             foreach (var item in words)
  24.             {
  25.                 Console.WriteLine(item);
  26.             }
  27.         }
  28.     }
  29. }
  30.  
Add Comment
Please, Sign In to add comment