lundi 4 mai 2015

c# provide 1 word and print different combinations of it

I have to input a 5 lettered word and then it should print out different 3 lettered combinations of it but it isn't working and I'm not sure why.

E.g. If I input "hello", all different combinations such as "leh", "lol", "hle" etc should return. Thank you in advance for your help ^^

static void Main(string[] args)
    {
        Console.Write("Enter a five-letter word: ");
        String x = Console.ReadLine();

        for(int i=0; i<x.Length; i++)
        {
            char letter = x[i];
            Random ran = new Random();
            for(int z=1; z<4; z++)
            {
                char y = x[ran.Next(0, x.Length)];
                Console.Write(y);
            }
        }
        Console.WriteLine();
    }




Aucun commentaire:

Enregistrer un commentaire