Advertisement
Katina_

Randomize_Words

Jun 25th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Randomize_Words
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string[] text = Console.ReadLine().Split();
  12.             int firstWord = 0;
  13.             int secondWord = 0;
  14.  
  15.             Random randomText = new Random();
  16.  
  17.             for (int i = 0; i < text.Length; i++)
  18.             {
  19.                 firstWord = randomText.Next(0, text.Length);
  20.                 secondWord = randomText.Next(0, text.Length);
  21.  
  22.                 string changeText = text[firstWord];
  23.                 text[firstWord] = text[secondWord];
  24.                 text[secondWord] = changeText;
  25.             }
  26.  
  27.             foreach (var word in text)
  28.             {
  29.                 Console.WriteLine(word);
  30.             }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement